BottomNavigationView 菜单项标题在非活动状态时不显示 [XML]

yop*_*e97 3 xml android

现在:https : //i.stack.imgur.com/lgdaa.png

我有一个底部导航栏。案例:底部导航栏项菜单的文本未显示在非活动状态时显示。文本仅在选项卡处于活动状态时显示。即使选项卡菜单处于非活动状态,应该显示什么图标标题?

<android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="?android:attr/windowBackground"
            android:theme="@style/BottomNavigationTheme"
            app:menu="@menu/menu"/>
Run Code Online (Sandbox Code Playgroud)

和样式:

    <style name="BottomNavigationTheme" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">@color/tabActive</item>
        <item name="android:textColorSecondary">@color/tabInactive</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

Abh*_*waj 11

是您正在寻找的方法。

或者在 XML 中,

app:labelVisibilityMode="labeled"
Run Code Online (Sandbox Code Playgroud)

希望能帮到你


Nic*_*zzi 5

文档中可以看到:

LABEL_VISIBILITY_AUTO 当有3 个或更少的项目时,标签的行为为“已标记” ;当有 4 个或更多的项目时,标签的行为为“已选择”。

在您的屏幕截图中,您有 4 个标签,因此继承的可见性为LABEL_VISIBILITY_SELECTED

您需要将可见性模式设置为labeled。直接从 XML 执行此操作:

<android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="?android:attr/windowBackground"
            android:theme="@style/BottomNavigationTheme"
            app:labelVisibilityMode="labeled"
            app:menu="@menu/menu"/>
Run Code Online (Sandbox Code Playgroud)