相关疑难解决方法(0)

如何在ActionBar中显示自定义视图?

我想在操作栏中显示自定义搜索(我正在使用ActionBarSherlock).

我明白了:

在此输入图像描述

但我想让自定义布局(edittext字段)占用整个可用宽度.

我按照这里的建议实现了自定义布局.

有我的自定义布局search.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="?attr/actionButtonStyle"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_horizontal"
    android:focusable="true" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|fill_horizontal" >

        <EditText
            android:id="@+id/search_query"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center"
            android:background="@drawable/bg_search_edit_text"
            android:imeOptions="actionSearch"
            android:inputType="text" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center_vertical"
            android:src="@drawable/ic_search_arrow" />

    </FrameLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

并在MyActivity:

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setIcon(R.drawable.ic_action_search);

LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.search, null);

actionBar.setCustomView(v);
Run Code Online (Sandbox Code Playgroud)

如何使自定义布局占用所有可用宽度actionBar

请帮忙.

android actionbarsherlock android-actionbar

92
推荐指数
4
解决办法
10万
查看次数

如何在操作栏中将适配器设置为searchview

将自定义值设置为 Searchview Adapter

就像我们在自动完成和传递数组字符串中一样

我试过这段代码:

private void setupSearchView(MenuItem searchItem) {

    if (isAlwaysExpanded()) {
        mSearchView.setIconifiedByDefault(false);
    } else {
        searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    }

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (searchManager != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        mSearchView.setSearchableInfo(info);

    }
    mSearchView.setOnQueryTextListener(this);
}
Run Code Online (Sandbox Code Playgroud)

android searchview

4
推荐指数
1
解决办法
2万
查看次数