菜单项未显示

时间:2017-03-19 00:35:51

标签: android

我正在尝试在我的Android应用中实现标签式菜单栏,但是我添加到菜单中的任何<item />都没有显示在预览中(见下图)。

menu / menu_navigation.xml的预览:

(菜单/ menu_navigation.xml中包含的<item />未显示)

item not displayed in Android Preview

菜单/ menu_navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>

<item
    android:id="@+id/bMenu"
    android:title="@string/app_name"
    android:icon="@drawable/ic_home"
    app:showAsAction="ifRoom"
    />

activity_main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:design="http://schemas.android.com/apk/res-auto"
tools:context="com.engineeringeric.parkerapp.MainActivity">

<android.support.design.widget.BottomNavigationView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    design:menu="@menu/menu_navigation">
</android.support.design.widget.BottomNavigationView>

1 个答案:

答案 0 :(得分:2)

在预览窗口中,模拟手机会尽可能地更改“无操作栏”,因为这会指示预览窗口隐藏您的菜单。

可能您的菜单不会出现在预览窗口中,而不是出现在实际情况中,即在您的手机或模拟器上可能会显示您的菜单。

让您的应用在您的手机或模拟器上运行,看看我是否正确。