Android sets the color and picture of the Selector in different states

Selector common state:

Android :state_selected control selected state, can be true or false

android:state_focused control gets focus state, can be true or false

android:state_pressed control click state, can be true or false

android:state_enabled control enable state, can be true or false

android:state_checkable control checkable state, can be true or false

android:state_checked control check state, can be true or false

 

Set the color in different states:

btn_enabled.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- 默认 -->
<item android:state_enabled="true">
<color android:color="#e25050" />
</item>
<item android:state_enabled="false">
<color android:color="#908e8e" />
</item>
</selector>

Set pictures in different states:

btn_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/btn_arrow_left_pressed" />
<item android:state_window_focused="true" android:state_focused="true" android:drawable="@drawable/btn_arrow_left_pressed" />
<item android:state_window_focused="false" android:state_focused="false" android:drawable="@drawable/btn_arrow_left_normal" />
</selector>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326530658&siteId=291194637