I want the keyboard to appear automatically when certain fragments are open in my application. To this end, I created an extension function showKeyboard()
:
fun EditText.showKeyboard() {
this.requestFocus()
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
imm?.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
}
This function works very well in fragments, but for some reason, it doesn't work in BottomSheets.
Here's how I use it in fragments (this works ✅ ):
override fun onResume() {
super.onResume()
binding.nickEdit.showKeyboard()
}
Here's how I use it in BottomSheet (this doesn't work ❌):
override fun onResume() {
super.onResume()
binding.searchEdit.showKeyboard()
}
I have tried adding showkeyboard()
function to onViewCreated()
, but the keyboard still doesn't appear when the BottomSheet opens. How can I fix this?