The Preference class uses com.android.internal.R.layout.preference as its layout. This contains an ImageView for an icon on the left hand side, then the title and summary textviews and finally a widget_frame Layout on the right hand side. By calling PreferenceScreen.setIcon()
you can set the drawable to place in the icon image view. By calling PreferenceScreen.setWidgetLayoutResource()
you can set the layout to place in the widget_frame layout.
app:iconSpaceReserved=true
reserve a space for icon. To remove the space as shown in the below figure, set app:iconSpaceReserved=false
.
Layout for the above is
<?xml version="1.0" encoding="utf-8"?> <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <PreferenceCategory android:title="General" app:iconSpaceReserved="false"> <ListPreference android:key="@string/pref_font_size_text" android:title="Font Size" android:summary="Select the font size" android:defaultValue="12" android:entries="@array/pref_font_size_list_entry" android:entryValues="@array/pref_font_size_list_val" app:iconSpaceReserved="false"/> </PreferenceCategory> </androidx.preference.PreferenceScreen>