菜单项在菜单栏没有显示 [英] Menu items not shown in menu bar
问题描述
我有同样的问题,因为喜欢这里贴多次或<一个href=\"https://www.androidpit.com/forum/598727/please-help-i-can-not-get-icons-to-appear-in-action-bar\">here.我定义它显示了在preVIEW在菜单项 AndroidStudio
:
但是,当我的手机上运行的应用程序的图标(A PNG
图片)是不可见的,并且有大量的可用空间。然而,这种添加选项,在选项菜单中显示出来(到非常正确的;具有Srttings'在一起)。这里是我的 menu.xml文件
:
&LT;菜单的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
的xmlns:工具=http://schemas.android.com/tools
工具:上下文=MainActivity。&GT; &LT;项目机器人:ID =@ + ID / action_favourite
机器人:图标=@的mipmap / ic_add
机器人:标题=@字符串/ menu_add
机器人:showAsAction =总是/&GT;
&LT;项目机器人:ID =@ + ID / action_settings机器人:标题=@字符串/ action_settings
机器人:orderInCategory =100的应用程序:showAsAction =从不/&GT;&所述; /菜单&gt;
我试过的建议,我能找到,但他们没有解决我的问题。我的手机是一款LG G3。我怎样才能解决这个问题?
其他信息: onCreateOptionsMenu
@覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
//充气菜单;如果是present这增加了项目操作栏。
。getMenuInflater()膨胀(R.menu.menu_main,菜单);
返回true;
}
只需使用应用:showAsAction =总是
和的xmlns:应用= http://schemas.android.com/apk/res-auto
然后它会显示出来。
&LT;菜单的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
的xmlns:工具=http://schemas.android.com/tools
工具:上下文=MainActivity。&GT; &LT;项目机器人:ID =@ + ID / action_favourite
机器人:图标=@的mipmap / ic_add
机器人:标题=@字符串/ menu_add
应用:showAsAction =总是/&GT;
&LT;项目机器人:ID =@ + ID / action_settings
机器人:标题=@字符串/ action_settings
机器人:orderInCategory =100
应用:showAsAction =从不/&GT;&所述; /菜单&gt;
您可能正在使用支持库,它是依赖于应用程序的命名空间。如果有疑问,只需添加相同的属性两次(的android:
和应用程序:
命名空间)。
I have the same problem as posted many times like here or here. I define a menu item which shows up in the preview in AndroidStudio
:
But when I run the app on my phone the icon (a png
image) is not visible, and there is a lot of space available. However, this 'Add' option shows up in the Options menu (to the very right; together with 'Srttings'). Here is my menu.xml
:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item android:id="@+id/action_favourite"
android:icon="@mipmap/ic_add"
android:title="@string/menu_add"
android:showAsAction="always"/>
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
I tried the suggestions I could find, but none of them solved my problem. My phone is a LG G3. How can I solve this problem?
Additional information: onCreateOptionsMenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Just use app:showAsAction="always"
and xmlns:app="http://schemas.android.com/apk/res-auto"
then it will show.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item android:id="@+id/action_favourite"
android:icon="@mipmap/ic_add"
android:title="@string/menu_add"
app:showAsAction="always"/>
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
You're probably using the support library which is dependent on the app namespace. If in doubt, just add the same property twice (android:
and app:
namespaces).
这篇关于菜单项在菜单栏没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!