[英]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.