本文介绍了始终在支持操作栏中显示菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用android应用程序.我已经在其中实现了受支持的操作栏.我想始终显示选项菜单项.但是它没有显示出来.它显示在下拉菜单中.我的菜单项代码如下.
I am working on android application . I have implemented supported action bar in it .I want to show option menu item always . But it is not showing . it is showing in drop down menu . my code for menu item given below.
<item
android:id="@+id/action_settings"
android:icon="@drawable/add_post"
android:title="@string/action_settings"
/>
下面是ActionBar Activity的代码:-
And code of ActionBar Activity is given below:-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
任何帮助将不胜感激.
推荐答案
来自文档您应该将showAsAction
属性添加到always
或ifRoom
From docsyou should add showAsAction
attribute to always
or ifRoom
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>
这篇关于始终在支持操作栏中显示菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!