I would like to know if you can change the colors of these CheckBox
which is currently green (default color) to the accent color of my app .
You can customize through style.xml
, the result should look something like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- Add this -->
<item name="android:dialogTheme">@style/DialogStyle</item>
<item name="android:alertDialogTheme">@style/DialogStyle</item>
</style>
<!-- Personalize a cor aqui -->
<style name="DialogStyle" parent="android:Theme.Material.Dialog">
<item name="android:colorAccent">@color/colorAccent</item>
</style>
You need to create a selector like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/checked" />
<item android:state_checked="false" android:drawable="@drawable/unchecked" />
</selector>
Save it to the res / drawables / folder with the name of cb_selector.xml
Then when you declare your checkbox, put it as a button, like this:
<CheckBox
android:id="@+id/cb"
android:text="My CheckBox"
android:button="@drawable/cb_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>