简体   繁体   中英

Change ListPreference style

I want to change default image of a ListPreference by creating a new style .

I did it with a CheckBoxPreference by inherit Widget.CompoundButton.CheckBox and setting a new android:button , but I don't know how to do it on a ListPreference .

You can add an icon in the preference using the WidgetLayout property.

Example:

<EditTextPreference
    android:defaultValue=""
    android:dialogTitle="@string/mode_name"
    android:key="mode_name"
    android:order="0"
    android:summary=""
    android:title="@string/mode_name"
    android:widgetLayout="@layout/mode_item_preference"
     />

And the mode_item_preference.xml

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/app_name"
    android:focusable="false"
    android:src="@drawable/delete" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM