-1

I was trying to set the following attribute of BottomNavigationView widget

app:itemTextColor="@color/text_color"

But this sets the text color of active and inactive item both. I want to have different text color on active and inactive item of BottomNavigationView.

BeeProDev
  • 159
  • 1
  • 2
  • 13

1 Answers1

1

First, you have to make a selectable color in res>color>selectable_color

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

Then you have to set this selectable color as itemTextColor in BottomNavigationView widget

app:itemTextColor="@color/selectable_text_color"
BeeProDev
  • 159
  • 1
  • 2
  • 13
  • @SyedRafaqatHussain Can I know why you edited this and what mistake you found? How can you add a `Drawable` resource file to the `Color` resource file? – M DEV Apr 24 '22 at 05:53
  • 2
    @MDev because it is color selector not a drawable selector – Syed Rafaqat Hussain Apr 24 '22 at 06:26
  • 2
    @MDev attribute of BottomNavigationView requires a color file not a drawable file. Kindly give it a try you'll be clear – BeeProDev Apr 24 '22 at 06:32
  • @SyedRafaqatHussain @BeeDeveloper I don't know why you all adding `Selector` in the `color resource`? checkout this answer https://stackoverflow.com/a/51580222/16765223 – M DEV Apr 24 '22 at 06:36
  • @SyedRafaqatHussain and checkout this also https://stackoverflow.com/a/65503475/16765223 – M DEV Apr 24 '22 at 06:39
  • @MDev text selector is created in the color directory in the resource directory not in the color file because the itemTextColor requires color not drawable. – Syed Rafaqat Hussain Apr 24 '22 at 06:51
  • @SyedRafaqatHussain I already used this code to change my text and item color. Check out this answer https://stackoverflow.com/a/65503475/16765223 – M DEV Apr 24 '22 at 07:03