我有一个复选框,我想改变它的颜色。我附上一张照片以便更多了解。
我想将黑色方块颜色更改为白色,就像文本一样#34;按跳过"。我的xml代码如下:
<CheckBox
android:id="@+id/checkBox1"
android:background="@drawable/tutorial_screen_edit_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCheckboxClicked"
android:text="Press to Skip"
android:textColor="@color/white"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
答案 0 :(得分:2)
答案很简单,请查看下面的代码段:
<CheckBox
android:id="@+id/checkBox1"
android:background="@drawable/tutorial_screen_edit_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCheckboxClicked"
android:text="Press to Skip"
android:buttonTint="@color/white" <!--just add this line-->
android:textColor="@color/white"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
答案 1 :(得分:0)
在drawalbe文件夹中定义自己的drawalbe
checkbox_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/checkbox"
android:state_checked="false"/>
<item android:drawable="@drawable/checkboxselected"
android:state_checked="true"/>
<item android:drawable="@drawable/checkbox"/>
</selector>
your_layout.xml
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/checkbox_selector"
android:text="CheckBox"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/Black" />
答案 2 :(得分:0)
尝试使用ColorStateList
ColorStateList colorStateList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_checked}, // unchecked
new int[]{android.R.attr.state_checked} , // checked
},
new int[]{
Color.parseColor("#000000"), //unchecked color
Color.parseColor("#FFFFFF"), //checked color
}
);
使用以下设置颜色:setButtonTintList()
CheckBox cb = (CheckBox) findViewById(R.id.checkBox1);
CompoundButtonCompat.setButtonTintList(cb,colorStateList);
答案 3 :(得分:0)
试试这个。
<CheckBox
android:id="@+id/chk_remember_signup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="hello" />