Change Background Color of TextView on Click

后端 未结 1 1581
我在风中等你
我在风中等你 2021-01-14 10:09

I need to change the background color of a TextView.

the font color using ColorStateList what I can change, but the background color does not accept ColorStateList

相关标签:
1条回答
  • 2021-01-14 10:17

    You will need to set the backgroundDrawable for the TextView. I've only done my state lists in XML and it would be something like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true">
            <color android:color="#00ff00" />
        </item>
        <!-- And so on -->
    </selector>
    

    From what I understand, from the documentation if you want to do the state list in Java code you will need to use the StateListDrawable

    0 讨论(0)
提交回复
热议问题