Android学习笔记StateListDrawable文件

SateListDrawable,可包含一个 Drawable 数组,让目标组件在不同状态显示不同 Drawable。对应的 xml 文件的根节点

示例

edittext_focused.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:color="#f60"></item>
    <item android:state_focused="false" android:color="#0a0"></item>
</selector>

activity_main.xml

<EditText
        android:id="@+id/editText"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@drawable/edittext_focused"
        android:text="生活好枯燥啊!"/>
    <EditText
        android:id="@+id/editText2"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@drawable/edittext_focused"
        android:text="生活好枯燥啊!"
        />

效果:

原文地址:https://www.cnblogs.com/lzpq/p/12879497.html