Create a color folder under the res directory, create a state selector in it, and set the selected effect color to change.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:color="@color/green_00bc9c"></item>
<item android:state_checked="false" android:color="@color/grey_999"></item>
</selector>
set directly in the layout file
android:textColor=“@color/color_radiobutton”
Then the direct background and the click effect of the radioButton are realized together
Directly referenced in the layout
android:background=“@drawable/screen_radio”
Create a state selector below the drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="false"
android:drawable="@drawable/btn_write_selector" />
<item
android:state_checked="true"
android:drawable="@drawable/btn_selector" />
</selector>
Then create btn_selector under drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/grey_btn_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/bg_text_normal" android:state_pressed="false"/>
</selector>
btn_write_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/lightest_gray" android:state_pressed="true"></item>//按下
<item android:drawable="@color/white"></item>//松开
</selector>
That's it.
Zhang Jinlin
https://editor.csdn.net/md/?articleId=128176325