Android选项卡文本颜色选择器忽略按下的状态

Android选项卡文本颜色选择器忽略按下的状态,android,android-styles,textcolor,Android,Android Styles,Textcolor,我创建了自己的android主题来改变actionbar标签的外观。问题是textcolor选择器似乎忽略了state_pressed属性,因此即使按下此选项卡,选项卡文本的颜色也始终相同。其他状态没有问题,例如,正确识别所选状态,并且所选选项卡具有文本颜色,这与未选择选项卡的文本颜色不同。 此外,我还为选项卡背景创建了选择器,它可以在按下状态时正常工作(如果按下选项卡,其背景颜色会改变) 下面是我的一些代码: styles.xml: <style name="Theme.MyTheme"

我创建了自己的android主题来改变actionbar标签的外观。问题是textcolor选择器似乎忽略了state_pressed属性,因此即使按下此选项卡,选项卡文本的颜色也始终相同。其他状态没有问题,例如,正确识别所选状态,并且所选选项卡具有文本颜色,这与未选择选项卡的文本颜色不同。

此外,我还为选项卡背景创建了选择器,它可以在按下状态时正常工作(如果按下选项卡,其背景颜色会改变)

下面是我的一些代码:

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>

@style/Theme.myteme.TabStyle
@style/Theme.myteme.TabTextStyle
...
@可绘图/背景选择器
@颜色/文本颜色选择器
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>

我尝试了所有方法都没有成功-state\u pressed属性似乎被忽略,但仅在textcolor\u选择器中。请帮我理解并解决这个问题

查看ActionBar样式文档的一节-其中提到
注意:应用于titleTextStyle的自定义样式应使用TextAppearance.Holo.Widget.ActionBar.Title作为父样式。
-可能有助于纠正此问题


另一个可以查看的地方是
示例主题下的
部分-它显示了一个
android:actionBarTabTextStyle的示例,可能有助于为您排序。

在drawable文件夹中尝试以下操作:



谢谢您的回复。不幸的是,我已经看到了你发布的两个链接,它们都没有帮助。Ad1。本说明是关于titletextstyle的,而不是关于tabtextstyle的。tabtextstyle的父层次结构正常。Ad2。这个例子甚至不使用文本颜色选择器,它使用特定的层次结构来支持android<3.0的设备。我使用“仅适用于Android 3.0及更高版本”一节中的层次结构。只是为了确保-您的textcolor\u选择器文件位于
res/color/
目录中?正如您在声明中指出的那样,
@color/textcolor\u选择器
可能没有什么区别,但在我在android文档中看到的所有示例中,
state\u pressed
位于其他选项之前,并且也列在第一位---尝试更改textcolor\u选择器文件中的
states
,在为每个
选择的
状态之前按
状态
,是的,我的文本颜色选择器文件位于res/color/中。我也尝试过@drawble/textcolor\u选择器和drawable目录,但仍然没有。属性的顺序应该不重要,但是我已经尝试在一开始就按下state_,但没有成功,我甚至尝试过这样的操作: