我正在使用 android 支持设计小部件 BottomNavigationView 来制作我的底部导航项。这是工作的结果:
它有 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/