android-支持库 BottomNavigationView 不显示标题

标签 android android-support-library android-support-design android-bottomnav

我正在使用 android 支持设计小部件 BottomNavigationView 来制作我的底部导航项。这是工作的结果: enter image description here

它有 2 个问题,首先它不显示项目下的标题,第二个问题我想让项目填充,我不想在导航上有可用空间,我只希望它们填充空间并划分项目之间的空间。

这是我的菜单代码:

    <?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/action_item1"
        android:icon="@drawable/phone"
        app:showAsAction="ifRoom"
        android:title="ارتباط" />

    <item
        android:id="@+id/action_item2"
        android:icon="@mipmap/ic_history"
        app:showAsAction="ifRoom"
        android:title="سوابق خرید" />

    <item
        android:id="@+id/action_item3"
        android:icon="@drawable/sabad"
        app:showAsAction="ifRoom"
        android:title="سبد خرید" />

    <item
        android:id="@+id/action_item4"
        android:icon="@drawable/market2"
        app:showAsAction="ifRoom"
        android:title="فروشگاه" />

</menu>

这是 xml 代码:

` <RelativeLayout
        android:id="@+id/activity_main"
        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"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.truiton.bottomnavigation.MainActivity">

        <FrameLayout
            android:id="@+id/frame_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/navigation"
            android:animateLayoutChanges="true">

        </FrameLayout>

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@color/colorPrimary"
            app:itemIconTint="#fff"
            app:itemTextColor="#F2F2F4"
            app:menu="@menu/bottom_navigation_items"/>
    </RelativeLayout>`

我该如何解决这个问题?

最佳答案

设计支持库 28.0.0 的

更新

在您的 xml 中使用 app:labelVisibilityMode="labeled"

旧答案 是支持库低于 28.0.0 的解决方法

你的第一个问题,来自指南 Bottom navigation

  • “如果有四个或五个操作,则仅将不活动的 View 显示为图标”

解决方案请查看 Android BottomNavigationView items showing without text also layout does not hiding on scroll

关于android-支持库 BottomNavigationView 不显示标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44237505/

相关文章:

java - Android - 在 Fragment 类中保存成员字段的值

android - 在 Android 按钮中设置可绘制的自定义宽度高度图像

android - MultiChoiceModeListener 支持早于 11 的 Android API 版本

Android 支持 v23.1.0 更新中断 NavigationView 获取/查找 header

android - 当我们有了 support-design 之后,还需要 support-v4 和 appcompat-v7 吗?

android - 自动更新 Android 应用程序

Android Room 数据库 DAO 调试日志

android - 为什么我不能导入 'androidx.core.app.NotificationChannelCompat' ?

android - 如何在 FragmentPagerAdapter (android.support.v4) 中使用 PreferenceFragment?

带有阴影的 Android 底部导航栏