Android 修改RadioButton圆圈颜色
2019-07-25 本文已影响0人
树蜂
只需设置buttonTint颜色:(仅适用于api level 21或更高版本):
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio"
android:checked="true"
android:buttonTint="@color/your_color"/>
在你的values / colors.xml中你的颜色在这种情况下是一个微红的:
<color name="your_color">#e75748</color>
结果:
如果你想通过代码(也是api 21和以上)来做到这一点:
if(Build.VERSION.SDK_INT>=21)
{
int _Color = Color.parseColor("#ff0000");
pBtn.setButtonTintList(ColorStateList.valueOf(_Color));
}
其他更多使用方法,请参照下面
https://www.programcreek.com/java-api-examples/?class=android.widget.RadioButton&method=setButtonTintList
本人使用最终使用如下的类
https://www.programcreek.com/java-api-examples/?code=jumaallan/AndelaTrackChallenge/AndelaTrackChallenge-master/app/src/main/java/com/androidstudy/andelatrackchallenge/utils/Easel.java