Set checkbox

I cannot configure my checkbox, although I defined the background in the xml preferences file, it does not pull out the file. 1. I am trying to display custom images for a checkbox and defined the xml selector as "android_button.xml", which looks like this:

<?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 the res> drawable folder.

2.my file checkbox preference.xml:

  <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 appears on the screen is android: the title text, if I change the text, it changes the text. Nothing else changes. How to fix it. Thank you for your suggestion.

+15
android android-emulator android-manifest
Aug 25 '10 at 19:15
source share
2 answers

There are two ways to achieve what you need by first defining the custom_chexbox.xml custom flag in 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"/> 

Then you need to specify this layout for preference:

 <CheckBoxPreference android:key="@string/Drop_Option" android:title="Close after call drop" android:defaultValue="true" android:widgetLayout="@layout/custom_checkbox"/> 

The second way is to create a custom theme, redefine the style for viewing the flags and apply the theme to the activity of preferences, see How to adjust the color of the CheckMark color in Android in the dialog: android for more details.

+43
Aug 26 '10 at 2:36
source share

Make one drwable xml file:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/checkbox_active_btn" android:state_checked="true"></item> <item android:drawable="@drawable/checkbox_active_btn" android:state_checked="true" android:state_enabled="false" android:state_focused="true"></item> <item android:drawable="@drawable/checkbox_active_btn" android:state_checked="true" android:state_enabled="false"></item> <item android:drawable="@drawable/checkbox_active_btn" android:state_checked="true" android:state_focused="true"></item> <item android:drawable="@drawable/checkbox_active_btn" android:state_checked="true" android:state_pressed="true"></item> <item android:drawable="@drawable/checkbox_inactive_btn" android:state_checked="false"></item> <item android:drawable="@drawable/checkbox_inactive_btn" android:state_checked="false" android:state_enabled="false" android:state_focused="true"></item> <item android:drawable="@drawable/checkbox_inactive_btn" android:state_checked="false" android:state_enabled="false"></item> <item android:drawable="@drawable/checkbox_inactive_btn" android:state_checked="false" android:state_focused="true"></item> <item android:drawable="@drawable/checkbox_inactive_btn" android:state_checked="false" android:state_pressed="true"></item> </selector> 

Install it programmatically cb.setButtonDrawable (R.drawable.checkboxcustom);

0
Jun 30 '16 at 7:13
source share



All Articles