Reputation: 217
I have a checkbox and i want to change its color. I am attaching a pic for more understanding.
I want to change the black squares color to white just like the text "Press to skip". My xml code is below:
<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" />
Upvotes: 3
Views: 4068
Reputation: 446
The answer is very simple, check this code snippet below:
<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" />
Upvotes: 6
Reputation: 1238
Try this one.
<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" />
Upvotes: 0
Reputation: 23881
try using 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
}
);
set the color using: setButtonTintList()
CheckBox cb = (CheckBox) findViewById(R.id.checkBox1);
CompoundButtonCompat.setButtonTintList(cb,colorStateList);
Upvotes: 3
Reputation: 4342
define your own drawalbe in drawalbe folder
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" />
Upvotes: 0