【问题标题】:TextView state_pressed/state_focused/state_selected style changeTextView state_pressed/state_focused/state_selected 样式改变
【发布时间】:2011-12-25 06:26:54
【问题描述】:

我正在尝试根据其状态更改 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") 时它不起作用。 有什么建议吗?
谢谢

【问题讨论】:

  • 你有没有把你的styles.xml保存在res->values文件夹中???

标签: android coding-style textview selector pressed


【解决方案1】:

问题在于style="@drawable/text_ops" 这行应该是style="@style/text_ops"。

我没有尝试过使用样式选择器,但如果能这样工作会很酷。

【讨论】:

  • 是的,我知道你的意思。我也认为将 styles 选择器文件放在 drawables 文件夹中有点奇怪,但我认为不可能将选择器包含在 values/styles.xml 中.
【解决方案2】:

据我所知,在 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

【讨论】:

  • 谢谢 Maneesh,我想这就是问题所在。你知道任何解决方法吗?
猜你喜欢
  • 1970-01-01
  • 2014-11-26
  • 1970-01-01
  • 1970-01-01
  • 2016-08-05
  • 1970-01-01
  • 2016-07-05
  • 2011-09-15
  • 1970-01-01
相关资源
最近更新 更多