1

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?

guv4
  • 11
  • 1

1 Answers1

0

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

Set gradient color for text in Android Studio with Kotlin language

MMG
  • 3,226
  • 5
  • 16
  • 43
  • java.lang.RuntimeException: Unable to start activity ComponentInfo{com.x.x/com.x.x.activities.MainActivity}: android.view.InflateException: Binary XML file line #61 in com.x.x:layout/activity_main: Binary XML file line #61 in com.x.x:layout/activity_main: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView – guv4 Mar 09 '20 at 22:50
  • Caused by: android.view.InflateException: Binary XML file line #61 in com.x.x:layout/activity_main: Binary XML file line #61 in com.x.x:layout/activity_main: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView Caused by: android.view.InflateException: Binary XML file line #61 in com.x.x:layout/activity_main: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView – guv4 Mar 09 '20 at 22:51
  • Where did you set the line I said?! In '' you should put that line and you should omit ' app:itemTextColor="@drawable/test_gradient_colorstatelist" ' from your xml. – MMG Mar 10 '20 at 04:07
  • I did just that, replaced the colorstatelist with the line you suggested and it results in the errors I commented. I works fine with solid colors, but can't get it to work with a gradient – guv4 Mar 10 '20 at 08:25
  • You are right, I will search for your response. I hope to be successful. – MMG Mar 10 '20 at 08:52
  • I edited my answer, it help you to make a text gradient@guv4 – MMG Mar 12 '20 at 04:28