我正在尝试创建菜单,并添加一些操作" ifRoom"使用以下代码:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_search"
android:icon="@android:drawable/ic_menu_search"
android:actionViewClass="android.widget.SearchView"
android:showAsAction="ifRoom|collapseActionView"
android:title="@string/search_description" />
<item
android:id="@+id/menu_refresh"
android:title="@string/menu_refresh"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/menu_preference"
android:title="@string/menu_preferences"
android:showAsAction="never"
/>
</menu>
但我得到的是菜单显示在底部... 我希望它在屏幕的顶部......
知道这里发生了什么吗?谢谢!
屏幕截图链接:http://i.stack.imgur.com/knECg.png
以下是MainActivity.java onCreateOptionaMenu方法:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
// Moved from onCreate -- Retrieve the Search View and configure/enable it
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()) );
return true;
}