简体   繁体   English

如何设置 ChipNavigationBar 的文字颜色

[英]How to set text color of ChipNavigationBar

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity"
    android:id="@+id/fragment_container">

   <com.ismaeldivita.chipnavigation.ChipNavigationBar
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:padding="10dp"
       android:id="@+id/bottom_nav_menu"
       app:cnb_textColor ="@color/white"
       app:cnb_unselectedColor="@color/black"`enter code here`
       android:layout_marginBottom="5dp"
       app:cnb_menuResource="@menu/bottom_navigation_menu_chef"
       android:layout_alignParentBottom="true"
       />
</RelativeLayout>

How I can set the text color of the selected item using this library on any other way?如何以任何其他方式使用此库设置所选项目的文本颜色?

In menu item add app:cnb_textColor="@color/home_label"在菜单项中添加app:cnb_textColor="@color/home_label"

Create another XML file in res\color named something like text_color.xml.在 res\color 中创建另一个 XML 文件,命名为 text_color.xml。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- disabled state -->
  <item android:state_enabled="false" android:color="#9D9FA2" /> 
  <item android:color="#000"/>
</selector>

In menu item add app:cnb_textColor="@color/text_color"在菜单项中添加 app:cnb_textColor="@color/text_color"

As i see.. You can set the selected color changing the cnb_textColor in the bottom_navigation_menu_chef .如我所见..您可以在bottom_navigation_menu_chef中设置更改cnb_textColor的选定颜色。

I will get you an example:我给你举个例子:

<?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/home"
        android:icon="@drawable/ic_home"
        android:title="Home"
        app:cnb_textColor="@android:color/holo_red_dark"/>

    <item
        android:id="@+id/activity"
        android:icon="@drawable/ic_activity"
        android:title="Activity"
        app:cnb_textColor="@android:color/holo_green_dark"/>

    <item
        android:id="@+id/favorites"
        android:icon="@drawable/ic_heart"
        android:title="Favorites"
        app:cnb_textColor="@android:color/black"/>

    <item
        android:id="@+id/settings"
        android:icon="@drawable/ic_settings"
        android:title="Settings"
        app:cnb_textColor="@android:color/holo_blue_light" />

</menu>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM