'How to open keyboard automatically in EditTextPreference?
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
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.
Solution 1:[1]
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)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tenfour04 |

