TextView state_pressed/state_focused/state_selected样式更改

tre*_*ter 7 android coding-style pressed selector textview

我正在尝试根据其状态更改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>
Run Code Online (Sandbox Code Playgroud)

我的selector(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>
Run Code Online (Sandbox Code Playgroud)

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

Man*_*esh 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