0

Legacy ListPreference in Android comes with :

protected void onPrepareDialogBuilder(android.app.AlertDialog.Builder builder)

That could be use to modify rows in the displayed dialog... see custom row in a listPreference?

This method is not available anymore in the androix.preference library wondering how to achieve rows customization in the displayed dialog when using androix.preference support library ?

avianey
  • 5,306
  • 3
  • 30
  • 58

1 Answers1

0

One should override PreferenceFragmentCompat#onDisplayPreferenceDialog(preference: Preference) to display a custom preference dialog :

override fun onDisplayPreferenceDialog(preference: Preference) {
    if (preference.key == MY_CUSTOM_DIALOG_KEY) {
        if (parentFragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) {
            // already displayed to user
            return
        }
        MyCustomPreferenceDialogFragment.newInstance(preference.key).let {
            it.setTargetFragment(this, 0)
            it.show(parentFragmentManager, DIALOG_FRAGMENT_TAG)
        }
    } else {
        super.onDisplayPreferenceDialog(preference)
    }
}

To implement your custom preference dialog fragment, you can have a look at implementations from support library :

  • PreferenceDialogFragmentCompat
avianey
  • 5,306
  • 3
  • 30
  • 58