Android text查看状态\按下/状态\聚焦/状态\选定样式更改
我正在尝试根据其状态更改TextView样式。 My styles.xml包含:Android text查看状态\按下/状态\聚焦/状态\选定样式更改,android,coding-style,textview,selector,pressed,Android,Coding Style,Textview,Selector,Pressed,我正在尝试根据其状态更改TextView样式。 My 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:textS
<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>
但是,当我将此应用于我的textview(style=“@drawable/text_ops”
)时,它不起作用。
有什么建议吗?谢谢问题在于行
style=“@drawable/text\u ops”
这应该是style=“@style/text\u ops”
我还没有尝试过使用样式选择器,但如果这样做的话会很酷。据我所知,android中只有两种状态列表1。颜色状态列表资源2。状态列表可绘制。如果您在其中使用样式,请重新检查文档 请查看下面的链接了解更多信息
你把你的styles.xml保存在res->values文件夹中了吗???谢谢Maneesh,我想这就是问题所在。你知道附近有什么工作吗?是的,我知道你的意思。我还认为将样式选择器文件放在drawables文件夹中有点奇怪,但我认为不可能将选择器包含在
values/styles.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>