StateListDrawable对应selector标签,每个Drawable对应着View的一种状态,系统会根据View的状态选择合适的drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize="false"
android:dither="true"
android:variablePadding="false">
<item android:drawable="@mipmap/picture"
android:state_pressed="true"
android:state_focused="true"
android:state_hovered="true"
android:state_selected="true"
android:state_checkable="true"
android:state_checked="true"
android:state_enabled="true"
android:state_activated="true"
android:state_window_focused="true"/>
</selector>
android:constantSize=”false”——StateListDrawable的大小是否不随着其状态的改变而改变,一般情况下为fasle
android:dither=”true”——是否开启抖动效果,默认为true
android:variablePadding=”false”——StateListDrawable的padding表示是否随着其状态的改变而改变,默认为false
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize="false"
android:dither="true"
android:variablePadding="false">
<!--按下的状态-->
<item android:drawable="@mipmap/picture"
android:state_pressed="true"/>
<!--获取焦点的状态-->
<item android:drawable="@mipmap/picture"
android:state_focused="true"/>
<!--默认状态-->
<item android:drawable="@mipmap/picture"/>
</selector>