开发者

State list drawable for textview

开发者 https://www.devze.com 2023-03-28 20:54 出处:网络
I just want to put a text, for example in blue, and when i press it to turn in another color. But not like setTextColor(int) but more like a link, that\'s why i why thinking about state list drawable.

I just want to put a text, for example in blue, and when i press it to turn in another color. But not like setTextColor(int) but more like a link, that's why i why thinking about state list drawable. Do you kno开发者_高级运维w how can i implement this ?


You can use colors instead of drawables for that. Use some thing like this:

file: res/color/state_white_blue.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_focused="true"
        android:state_pressed="true"
        android:color="@color/text_white" />
    <item
        android:state_focused="false"
        android:state_pressed="true"
        android:color="@color/text_white" />
    <item
        android:state_focused="true"
        android:color="@color/text_white" />
    <item
        android:state_selected="true"
        android:color="@color/text_white" />
    <item
        android:state_checked="true"
        android:color="@color/text_white" />
    <item
        android:state_selected="false"
        android:state_checked="false"
        android:state_focused="false"
        android:state_pressed="false"
        android:color="@color/text_blue" />
</selector>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号