7

我正在尝试根据其状态更改 TextView 样式。我的styles.xml 包含:

<style name="text_normal_ops">  
    <item name="android:gravity">left</item>  
    <item name="android:textColor">@color/text_usual_color</item> 
    <item name="android:textStyle">bold</item>  
</style>  
<style name="text_normal_ops_pressed">  
    <item name="android:gravity">left</item>  
    <item name="android:textColor">@color/text_pressed</item>  
    <item name="android:textStyle">bold</item>  
</style>

我的选择器 ( text_ops.xml) 定义为:

<selector xmlns:android="http://schemas.android.com/apk/res/android">  
    <item android:state_pressed="true" style="@style/text_normal_ops_pressed" />  
    <item android:state_focused="true" style="@style/text_normal_ops_pressed" />  
    <item android:state_selected="true" style="@style/text_normal_ops_pressed" />  
    <item style="@style/text_normal_ops"/>  
</selector>

但是当我将它应用到我的 textview ( style="@drawable/text_ops") 时它不起作用。有小费吗?
谢谢

4

2 回答 2

8

据我所知,在 android 中只有两个状态列表 1. 颜色状态列表资源 2. StateListDrawable。如果您在其中使用样式,请重新检查文档

请查看以下链接以获取更多信息

  1. http://developer.android.com/guide/topics/resources/color-list-resource.html
  2. http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
于 2011-11-09T12:13:57.250 回答
0

问题是style="@drawable/text_ops"应该是 style="@style/text_ops" 的那一行。

我还没有尝试使用样式选择器,但如果它可以这样工作会很酷。

于 2011-11-09T12:11:07.013 回答