我想在我的一个项目中改变RadioButton的圆圈的颜色,但我不知道该设置哪个属性。背景颜色是黑色的,所以它是看不见的。我想把圆圈的颜色设置为白色。


当前回答

它有一个XML属性:

android:buttonTint="yourcolor"

其他回答

设置buttonTint属性。例如,android:buttonTint="#99FF33"。

这个kotlin扩展

fun RadioButton.setLangRadioColor(isCheck: Boolean) { val color = if (isCheck) { intArrayOf( ContextCompat.getColor(rootView.context, R.color.light_red), ContextCompat.getColor(rootView.context, R.color.light_red) ) } else { intArrayOf( ContextCompat.getColor(rootView.context, R.color.sortRadioUnselectColor), ContextCompat.getColor(rootView.context, R.color.sortRadioUnselectColor) ) } val colorStateList = ColorStateList( arrayOf( intArrayOf(-android.R.attr.state_enabled), // disabled intArrayOf(android.R.attr.state_enabled) // enabled ), color ) this.buttonTintList = colorStateList }

要以编程方式更改单选按钮的颜色,您可以使用以下方法:

yourradio button name.buttonDrawable?.setColorFilter(Color.parseColor( color_value), PorterDuff.Mode.SRC_ATOP)

你必须使用以下代码:

<android.support.v7.widget.AppCompatRadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Radiobutton1"
                    app:buttonTint="@color/black" />

使用app:buttonTint而不是android:buttonTint和android.support.v7.widget。AppCompatRadioButton代替Radiobutton!

只需在<RadioButton>标签上使用android:buttonTint="@color/colorPrimary"属性。