1

I have multiple EditTextPreference in my project and I want to open keyboard automatically once I tap on any of the options. Right now I have to tap on the empty space to bring out the keyboard

enter image description here

This is one of the options.

I have tried using this : https://stackoverflow.com/a/14759538/9062752 but clearly it doesn't work because it is an edit text preference and not an edit text, so I cannot access it with an ID instead I have to use a key.

oyeraghib
  • 878
  • 3
  • 8
  • 26

1 Answers1

0

From browsing the source code, I think you could override onDisplayPreferenceDialog in your PreferenceFragment to get a reference to the DialogFragment and then the dialog. Then you could follow the code from the question you linked. Something like this (I didn't test it):

override fun onDisplayPreferenceDialog(preference: Preference) {
    super.onDisplayPreferenceDialog(preference)
    parentFragmentManager.fragments
        .filterIsInstance<EditTextPreferenceDialogFragmentCompat>()
        .firstOrNull { it.isVisible }
        ?.dialog
        ?.window?.setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE)
}
Tenfour04
  • 83,111
  • 11
  • 94
  • 154