Android tabs colorcolor selector ignores state_pressed
I created my own Android theme to change the appearance of the tabs in the action bar. The problem is that the color print selector seems to ignore the state_pressed attribute, so the text color of a tab is always the same even if that tab is clicked. No problem with other states, for example state_selected is correctly recognized and the selected tab has a text color that is different from the text color of the unselected tabs.
Also, I also created a selector for the background of the tabs and it works fine with state_pressed (if the tab is clicked, the background color changes).
There are several parts to my code:
styles.xml:
<style name="Theme.MyTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabStyle">@style/Theme.MyTheme.TabStyle</item>
<item name="android:actionBarTabTextStyle">@style/Theme.MyTheme.TabTextStyle</item>
</style>
...
<style name="Theme.MyTheme.TabStyle"
parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">@drawable/background_selector</item>
</style>
<style name="Theme.MyTheme.TabTextStyle"
parent="@android:style/Widget.Holo.Light.ActionBar.TabText">
<item name="android:textColor">@color/textcolor_selector</item>
</style>
background_selector.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:state_pressed="false">
<shape>
<solid android:color="#00ff00"/>
</shape>
</item>
<item android:state_selected="false" android:state_pressed="true">
<shape>
<solid android:color="#0000ff"/>
</shape>
</item>
<item android:state_selected="true" android:state_pressed="false">
<shape>
<solid android:color="#ff0000"/>
</shape>
</item>
<item android:state_selected="true" android:state_pressed="true">
<shape>
<solid android:color="#ffff00"/>
</shape>
</item>
</selector>
textcolor_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:state_pressed="false"
android:color="#ff0000"/>
<item android:state_selected="true" android:state_pressed="true"
android:color="#0000ff"/>
<item android:state_selected="false" android:state_pressed="false"
android:color="#ffff00"/>
<item android:state_selected="false" android:state_pressed="true"
android:color="#00ff00"/>
</selector>
I've tried everything without success - the state_pressed attribute seems to be ignored, but only in the textcolor_selector. Please help me figure out and solve this problem.
source to share
Check out the "Customize Text Color" section in the ActionBar Styling documentation - it mentions that Note: The custom style applied to titleTextStyle should use TextAppearance.Holo.Widget.ActionBar.Title as the parent style.
- maybe a change could help fix the problem.
Another place to look - here in the section Example theme
- is an example android:actionBarTabTextStyle
that might help sort things for you.
source to share
Try it:
<item android:state_enabled="true">
<shape>
<corners android:radius="0dp" />
<solid android:color="@color/white" />
<stroke android:width="1dp" android:color="@color/color_700" />
<padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
</shape>
</item>
<item android:state_enabled="false">
<shape>
<corners android:radius="0dp" />
<solid android:color="@color/color_100" />
<stroke android:width="1dp" android:color="@color/bloqueado" />
<padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
</shape>
</item>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape>
<corners android:radius="0dp" />
<solid android:color="@color/white" />
<stroke android:width="1dp" android:color="@color/color_700" />
<padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
</shape>
</item>
<item android:state_enabled="false">
<shape>
<corners android:radius="0dp" />
<solid android:color="@color/color_100" />
<stroke android:width="1dp" android:color="@color/bloqueado" />
<padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
</shape>
</item>
</selector>
source to share