Possible Duplicate:
Change icons of checked and unchecked for Checkbox for Android
customize check box preference
Is there any way to customize style of elements in PreferencesActivity
?
I was only able to change color text, background etc.
I want to also change the check mark and radio button style in CheckBoxPreference
and so on.
I'm interesting in API8 or greater.
Thanks for your help!
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:defaultValue="true"
android:key="vibrate"
android:summary="summary"
android:title="Some title"
android:widgetLayout="@layout/custom_checkbox" />
<CheckBoxPreference
android:defaultValue="true"
android:key="autorotate"
android:summary="summary"
android:title="auto rotate" />
</PreferenceScreen>
I understand what you are saying now. I thought you were just using normal CheckBox
inside your View
. You are using CheckBoxPreference
and the other Preference
Views
.
Ok, well the concept is very similar.
You need to define a custom widget layout. Do this in your res/layout
directory and call it custom_checkbox.xml
. We can use the CheckBox
as an example.
Define how you would like the CheckBoxPreference
to look with the custom widget layout you create in the res/layout
directory by using a CheckBox
. For instance:
<CheckBox
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/customCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/android_button"
android:clickable="false"
android:focusable="false" />
You can replace android:button
with any drawable
that you have found or designed.
Now you need to define your CheckBoxPreference
and setting its android:widgetLayout
to the custom CheckBox
you just defined in res/layout
. For example:
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/Drop_Option"
android:title="Close after call drop"
android:widgetLayout="@layout/custom_checkbox" />
If you are not using xml
for defining your layout
you can do it in code like this:
CheckBoxPreference checkBoxPreference = new CheckBoxPreference(this);
checkBoxPreference.setWidgetLayoutResource(R.layout.custom_checkbox);
Resources found that were similar to this question.
Konstantin Burov
Related links to extended questions from comments:
Also, how to change style of list item?
Also, I would like to add some paddings to list items.