android - 项目未显示在操作栏上

标签 android menu

我有一个操作栏,我不明白为什么使用这段代码操作栏内的菜单项没有显示。

主菜单.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.foo.activity" >

    <item
        android:id="@+id/button1"
        android:icon="@drawable/button1"
        android:onClick="clickEvent"
        android:showAsAction="ifRoom|withText"
        android:title="@string/button1">
        <item
            android:id="@+id/log_out"
            android:orderInCategory="100"
            android:showAsAction="never"
            android:title="@string/log_out"/>
    </item>

</menu>

// create action bar menu
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

它总是显示这个:

enter image description here

提前致谢。

最佳答案

尝试分开项目,因为 item 不允许包含在另一个 item 中。

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.foo.activity">

    <item
        android:id="@+id/button1"
        android:icon="@drawable/button1"
        android:onClick="clickEvent"
        android:showAsAction="always"
        android:title="@string/button1"/>
    <item
        android:id="@+id/log_out"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/log_out"/>

</menu>

关于android - 项目未显示在操作栏上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25590012/

相关文章:

android - 在 Flutter GridView 构建器中添加自定义项

android - 在Android中编写后台服务

android - 在现有联系人个人资料 android 中添加应用程序链接

android - NavigationView主题所选项目背景样式

java - 为什么 editText 中的文本没有水平居中?

Android achartengine 简单饼图

ruby-on-rails - 事件管理员 : How to customize the main menu (at the top of the page)?

html - 使列表元素在移动设备上不可见(响应式)

javascript - 我应该更改哪个类以使我的菜单边距不同于菜单项中的文本

css - 无法突出显示当前菜单项/页面 wordpress