I am unable to customize my checkbox , although I have defined the background in the xml preference file, it doesn't pull the file. 1. I am trying to display custom images for checkbox and have defined the selector xml as "android_button.xml" which looks like :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checkable="true"
android:drawable="@drawable/state_normal" /> <!-- pressed -->
<item android:state_checked="true"
android:drawable="@drawable/android_pressed" /> <!-- focused -->
<item android:drawable="@drawable/state_normal" /> <!-- default -->
</selector>
state_normal and android_pressed are two .png images in res>drawable folder.
2.my Checkbox preference.xml file is :
<CheckBoxPreference android:key="@string/Drop_Option"
android:title="Close after call drop"
android:defaultValue="true"
android:background="@drawable/android_button"
/>
Is there any error in the definition, The only change that shows up in screen is the android:title text, if I change the text, it changes the text. Nothing else changes. How do I fix this. Thank you for your suggestion.
Есть два способа добиться того, что вам нужно: во-первых, определить собственный макет флажка custom_chexbox.xml в res/layout:
<?xml version="1.0" encoding="UTF-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/checkbox" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:focusable="false"
android:clickable="false" android:button="@drawable/android_button"/>
Затем вам нужно указать этот макет для предпочтения:
<CheckBoxPreference android:key="@string/Drop_Option"
android:title="Close after call drop" android:defaultValue="true"
android:widgetLayout="@layout/custom_checkbox"/>
Второй способ – создать пользовательскую тему, переопределить стиль для флажков и применить тему к действию настроек, см. Как настроить цвет цвета галочки в Android в диалоговом окне. : android для подробностей.