I am trying to change both the button text color and the button background color when the button toggles between selected state and not. The background works perfectly, but the text just shows as pink (the default colorPrimary
, which I have changed).
res/drawable/map_button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false">
<shape android:shape="rectangle">
<corners android:radius="4dp"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners android:radius="4dp"/>
<solid android:color="@color/colorPrimary"/>
</shape>
</item>
</selector>
res/drawable/map_button_text.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false">
<color android:color="@color/colorPrimary"/>
</item>
<item android:state_selected="true">
<color android:color="@android:color/white"/>
</item>
</selector>
res/styles/styles.xml
<style name="Button.Map">
<item name="android:layout_height">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_margin">4dp</item>
<item name="android:background">@drawable/map_button_background</item>
<item name="android:textColor">@drawable/map_button_text</item>
</style>
Also, the text color never changes, it just stays pink all the time. I tried adding <item android:color="@color:/colorPrimary"/>
to be used as a default, but it still doesn't work.
Any ideas on what's causing it?