我有一个带有SearchView的工具栏和一个操作按钮,这就是我想要的: what i want
但是当我编码时,我的动作按钮会隐藏。没有溢出,我不知道为什么。像这样: now
这是我在 onCreateOptionsMenu :
中的代码MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.list, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
MenuItem searchViewItem = menu.findItem(R.id.search);
SearchView searchView = (SearchView) searchViewItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
return super.onCreateOptionsMenu(menu);
我的菜单:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
android:title="@android:string/search_go"
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView" />
<item android:id="@+id/memu_switch_location"
android:title="@string/action_settings"
android:icon="@android:drawable/ic_dialog_map"
android:orderInCategory="100"
app:showAsAction="always" />
那我该怎么办?谢谢大家:))
答案 0 :(得分:0)
尝试切换应用:showAsAction =&#34;始终&#34; to&#34; ifRoom&#34;如下:
<item android:id="@+id/search"
android:title="@android:string/search_go"
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView" />
<item android:id="@+id/memu_switch_location"
android:title="@string/action_settings"
android:icon="@android:drawable/ic_dialog_map"
android:orderInCategory="100"
app:showAsAction="ifRoom" />
答案 1 :(得分:0)
我还没有尝试,但我认为它可能对你有帮助:
将搜索的属性“showAsAction”更改为“ifRoom”:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
android:title="@android:string/search_go"
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView" />
<item android:id="@+id/memu_switch_location"
android:title="@string/action_settings"
android:icon="@android:drawable/ic_dialog_map"
android:orderInCategory="100"
app:showAsAction="always" />