如何自定义底部导航视图?

时间:2019-05-11 11:22:06

标签: android bottomnavigationview

我在应用程序中使用Bottom Navigation View。一切正常,但是当选择其中一项时,我需要添加选择的紫色 。我该如何实现?enter image description here

1 个答案:

答案 0 :(得分:1)

很简单, 在资源中创建一个颜色文件夹并粘贴以下xml nav_item_color_state.xml(我使用的是蓝色,请根据您的要求进行修改)

   <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#FF0096D6" android:state_checked="true" />
    <item android:color="#FF666666" />
</selector>

然后是“ itemIconTint”和“ itemTextColor”

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:background="#fff"
    app:itemIconTint="@color/nav_item_color_state"
    app:itemTextColor="@color/nav_item_color_state"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/navigation" />
相关问题