动作条行动项目不显示 [英] ActionBar Action Items not showing
问题描述
我有一个非常简单的code,但我能不能解决即使经过长时间的谷歌搜索的问题。我想在我的动作条的一些行动项目,但每当我运行的应用程序,我看到的是与App标志和称号,一个动作条,但没有行动项目
这将是巨大的,如果你能帮助我,可能是我只是缺少了最明显的事情;)
这就是我的ActionBarActivity方法:
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
//充气操作栏中使用的菜单项
MenuInflater充气= getMenuInflater();
inflater.inflate(R.menu.main_activity_actions,菜单);
返回super.onCreateOptionsMenu(菜单);
}
这是为动作条(名为main_activity_actions.xml)相关的.xml文件:
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目机器人:ID =@ + ID / ACTION_SEARCH
机器人:图标=@可绘制/ ic_action_search
机器人:标题=@字符串/ ACTION_SEARCH
机器人:showAsAction =总是/>
<项目机器人:ID =@ + ID / action_compose
机器人:图标=@可绘制/ ic_action_compose
机器人:标题=@字符串/ action_compose
机器人:showAsAction =总是/>
< /菜单>
这是因为如果使用支持AppCompat动作条图书馆,ActionBarActivity你应该比ActioBarSherlock或创建XML的菜单的标准方法不同的创建你的菜单默认的动作条。
那么试试这个code:
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto>
<项目机器人:ID =@ + ID / ACTION_SEARCH
机器人:图标=@可绘制/ ic_action_search
机器人:标题=@字符串/ ACTION_SEARCH
应用程序:showAsAction =总是/>
<项目机器人:ID =@ + ID / action_compose
机器人:图标=@可绘制/ ic_action_compose
机器人:标题=@字符串/ action_compose
应用程序:showAsAction =总是/>
< /菜单>
和报告,如果这个工程
请注意:检查额外的preFIX的xmlns:应用程序,它应该被用来代替
GL
i have a very simple code, but a problem that I cannot solve even after long google searching. I want to have some Action Items in my ActionBar, but whenever I run the App, all I see is a ActionBar with the App logo and the title, but no Action Items.
It would be great, if you could help me, probably I am just missing the most obvious thing ;)
Thats the method in my ActionBarActivity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
And this is the relevant .xml file for the ActionBar (named main_activity_actions.xml):
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="always" />
<item android:id="@+id/action_compose"
android:icon="@drawable/ic_action_compose"
android:title="@string/action_compose"
android:showAsAction="always"/>
</menu>
This is because if you use the support AppCompat ActionBar library and ActionBarActivity you should create your menus in a different than the standard way of creating xml menus in ActioBarSherlock or the default ActionBar.
So try this code :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
app:showAsAction="always" />
<item android:id="@+id/action_compose"
android:icon="@drawable/ic_action_compose"
android:title="@string/action_compose"
app:showAsAction="always"/>
</menu>
and report if this works
Note: check the extra prefix xmlns:app which should be used instead!
GL
这篇关于动作条行动项目不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!