Android选项卡textcolor选择器忽略state_pressed [英] Android tabs textcolor selector ignores state_pressed
问题描述
我创建了自己的android主题来更改操作栏标签的外观.问题在于textcolor选择器似乎忽略了state_pressed属性,因此即使按下此选项卡,选项卡文本的颜色也始终相同.其他状态没有问题,例如,可以正确识别state_selected且所选选项卡具有文本颜色,该颜色与未选中的选项卡文本颜色不同.
此外,我还为选项卡背景创建了选择器,并且与state_pressed一起使用时效果很好(如果按下了选项卡,则背景颜色已更改).
I have created my own android theme to change the look of the actionbar tabs. The problem is that textcolor selector seems to ignore state_pressed attribute, so the color of tab text is always the same, even if this tab is pressed. There is no problem with other states, for example state_selected is correctly recognized and selected tab has text color, which is different from unselected tabs text color.
What is more, i have also created selector for tabs background and it works fine with state_pressed (if the tab is pressed, it's backround color is changed).
我的代码有几段:
styles.xml:
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:
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
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>
我尝试了一切都没有成功-state_pressed属性似乎被忽略,但仅在textcolor_selector中.请帮助我理解和解决此问题.
I have tried everything without success - state_pressed attribute seems to be ignored, but only in textcolor_selector. Please, help me understand and solve this problem.
推荐答案
Review the Customize the Text Color section of 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.
- perhaps a change there might help correct the problem.
另一个值得一看的地方是此处 c1>部分-显示了android:actionBarTabTextStyle
的示例,该示例可能有助于为您排序.
Another place to look would be here under the Example theme
section - it shows an example of android:actionBarTabTextStyle
that might help get things sorted for you.
这篇关于Android选项卡textcolor选择器忽略state_pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!