BottomNavigationView's titles' color being a gradient

感情迁移 提交于 2021-02-07 10:25:10

问题


I need to make the titles in BottomNavigationView in android be of a gradient color.

<?xml version="1.0" encoding="utf-8"?>
<gradient xmlns:android="http://schemas.android.com/apk/res/android"
        android:startColor="@color/gradientLeft"
        android:endColor="@color/gradientRight"
        android:angle="0"/>

I have the colors set up and it works with e.g. icons on BtmNavView, but I can't get the titles to change their color to a gradient.

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/btmNav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="?attr/toolbarColor"
        android:theme="@style/Widget.BottomNavigationView"
        app:itemHorizontalTranslationEnabled="false"
        app:itemTextColor="@drawable/test_gradient_colorstatelist"
        app:layout_behavior="com.x.x.tools.BottomNavigationBehavior"
        app:menu="@menu/bottom_nav" />

I have a selector set up too, but to no effect with the titles.

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

Any ideas how can I change the color of the bottom titles to a gradient?


回答1:


See correct answer of this question, it may help you:

Set gradient color for text in Android Studio with Kotlin language



来源:https://stackoverflow.com/questions/60582383/bottomnavigationviews-titles-color-being-a-gradient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!