I want to create a custom list dialog when I click on a ListPreference in Settings Activity.
ListPreference in root_preferences.xml:
<ListPreference
android:icon="@drawable/pref_language"
app:defaultValue="en"
app:entries="@array/language_entries"
app:entryValues="@array/language_values"
app:iconSpaceReserved="false"
app:key="@string/prefkey_language"
app:summary="%s"
app:title="@string/language_title" />
I want it to have rounded corners, and I also want custom listitem views (e.g. images instead of the default radiobuttons).
Actual result:
Expected result:
Can I do this in a way that I use ListPreference, but replace @array entries with an adapter?
Is there any other way to achieve this without needing to get rid of the PreferenceScreen?


Meanwhile, I have found a solution. It's probably not the cleanest one, but it works for me. If anyone knows a better solution, don't hesitate to let us know.
Create a class that extends DialogPreference. Create as many classes as many custom dialogs you want to have, e.g. LanguagePreference, UnitPreference, etc.
Now you can use these in root_preferences.xml.
Create a class that extends DialogFragment (may be abstract). Remove default background and title in onViewCreated().
Extend classes from RoundedPreferenceDialog, e.g. LanguagePreferenceDialog, UnitPreferenceDialog.
Override onDisplayPreferenceDialog in SettingsFragment. Create a condition for each custom dialog you have.
Now you can display a custom dialog instead of the default one. You just have to customize it the way you want. To make it rounded, set the background of the root layout to a custom rounded layout.
dialogpreference_language.xml:
bg_dialog_rounded.xml:
Final result: