You can override onDisplayPreferenceDialog(preference: Preference?)
and create your own AlertDialog
The AlertDialog
supports radio buttons so actually you can create the same dialog which is presented from the preference library itself. When you show that dialog, you can apply the workaround fix for showing it in immersive mode.
override fun onDisplayPreferenceDialog(preference: Preference?) {
AlertDialog.Builder(context)
.setTitle(<titleResID>)
.setSingleChoiceItems(<itemsArrayResID>, 0) { dialog, which ->
(preference as ListPreference).value = this.resources.getStringArray(<valuesArrayResID>)[which]
dialog.dismiss()
}
.setPositiveButton(R.string.cancel) { _, _ -> }
.showImmersive()
}
Actually here I've created showImmersive()
extension method to the AlertDialog.Builder
using the workaround hack to show the alert dialogs in immersive mode
fun AlertDialog.Builder.showImmersive(): AlertDialog {
val alertDialog = create()
alertDialog.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
alertDialog.window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN)
alertDialog.show()
alertDialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
return alertDialog
}