Drawable 选择器 Android
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<stroke android:width="1dp" android:color="@android:color/black" />
</shape>
</item>
<item android:state_checked="false" >
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<stroke android:width="1dp" android:color="@android:color/white" />
</shape>
</item>
</selector>
Color 选择器 Android
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#7C7C7C" android:state_checked="false" />
<item android:color="#359DF5" android:state_checked="true" />
</selector>
此篇文章对选择器状态进行了讲解。
去掉 RadioButton 默认的选择器 参考:
XML 布局中 android:button="@null"
Java 代码 radioButton.setButtonDrawable(new StateListDrawable());
Kotlin 代码 radioButton { buttonDrawable = StateListDrawable() }
代码设置 TextView TabHost 的 Color Selector:
Java 代码 textView.setTextColor(AppCompatResources.getColorStateList(context, R.color.selector));
Kotlin 代码 radioButton { setTextColor(AppCompatResources.getColorStateList(ctx, R.color.selector)) }