[英]menu is not visible in Bottom Navigation bar using BottomNavigationView widget android
我正在尝试在导航栏底部添加5个图标。 这就是像pic1这样出来的。 当我点击下方,其它图标将出现一次只能有一个时间,在显示PIC2 。 我需要使其看起来像这张图片pic3 。 有人对代码出什么问题有任何想法吗?
这些是我正在使用的库:
implementation 'com.android.support:support-core-utils:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
这是我的底部导航布局视图:
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bottomNavViewBar"
android:background="@drawable/white_grey_border_top"
app:menu="@menu/bottom_navigation_menu">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
这是white_grey_border_top可绘制文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1dp">
<item
android:bottom="-1dp"
android:top="1dp"
android:right="-1dp"
android:left="-1dp">
<shape
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/grey" />
<solid
android:color="@color/white" />
</shape>
</item>
这是我的bottom_navigation_menu:
<?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/ic_house"
android:icon="@drawable/ic_house"
android:title="">
</item>
<item
android:id="@+id/ic_search"
android:icon="@drawable/ic_search"
android:title="">
</item>
<item
android:id="@+id/ic_circle"
android:icon="@drawable/ic_circle"
android:title="">
</item>
<item
android:id="@+id/ic_alert"
android:icon="@drawable/ic_alert"
android:title="">
</item>
<item
android:id="@+id/ic_android"
android:icon="@drawable/ic_android"
android:title="">
</item>
更新:当我将android:backgroundTint="#1091BF"
到我的底部导航布局视图中时,它可以工作,但背景为蓝色( pic4 )。 另外,我注意到,如果仅将white_grey_border_top可绘制文件中的android:color="@color/white"
更改为任何其他颜色,则所有图标都会显示。
尝试在底部导航布局视图中使用以下内容。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
android:background="@drawable/background"
>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:backgroundTint="#1091BF"
app:itemIconTint="#fff"
app:itemTextColor="#fff"
app:menu="@menu/navigation"/>
</android.support.constraint.ConstraintLayout>
确保添加依赖项
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.