Greetings ,
I have 2 themes, dark and light which will be applied on the of their respective buttons. For checkbox i have made 2 styles based on those two themes.
in XML
in themes.xml
</resources>
in styles.xml
in selector_checkbox.xml
For the style for checkbox in Dark, it works like a charm, but for the checkbox in light theme, once checkbox gets selected , only checked drawable is showing, no matter how many times if i deselect the checkbox.
Please help how to resolve it??
NOTE : if i use the selector in xml like android:button="@drawable/selector_checkbox"
then it works perfect.
I have 2 themes, dark and light which will be applied on the of their respective buttons. For checkbox i have made 2 styles based on those two themes.
in XML
Code:
<CheckBox
android:text="CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/checkBox2"
android:theme="?attr/check_style"/>
in attr.xml
<attr name="check_style" format="reference"/>
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="dark" parent="AppTheme">
<item name="check_style">@style/MyCheckBox1</item>
</style>
<style name="light" parent="AppTheme">
<item name="check_style">@style/MyCheckBox3</item>
</style>
in styles.xml
Code:
<style name="MyCheckBox1" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="colorControlNormal">@android:color/black</item>
<item name="colorControlActivated">@android:color/holo_orange_dark</item>
</style>
<style name="MyCheckBox3" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:drawable">@drawable/selector_checkbox</item>
</style>
Code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/apptheme_btn_check_on_focused_holo_light" android:state_checked="true" />
<item android:drawable="@drawable/apptheme_btn_check_off_focused_holo_light" android:state_checked="false" />
<item android:drawable="@drawable/apptheme_btn_check_on_focused_holo_light" android:state_pressed="true" />
<item android:drawable="@drawable/apptheme_btn_check_off_focused_holo_light"/>
</selector>
Please help how to resolve it??
NOTE : if i use the selector in xml like android:button="@drawable/selector_checkbox"
then it works perfect.
Last edited by a moderator:
