Tepes Lucian Victor
01/27/2023, 7:29 PMTextField
inside a DialogFragment
not showing the soft keyboard when focused? I swear it worked at some point but I’ve tried tried reverting / updating compose version and nothing seems to fix it.gildor
01/28/2023, 3:03 PMTepes Lucian Victor
02/01/2023, 7:45 AMgildor
02/01/2023, 8:32 AMTepes Lucian Victor
02/01/2023, 8:34 AMgildor
02/01/2023, 8:43 AMclass MyDialog : androidx.fragment.app.DialogFragment() {
...
override fun onResume() {
super.onResume()
// AlertDialog sets flag to prevent showing keyboard if custom view doesn't have EditText
// It of course cannot be detected with Compose (all composition is dynamic)
// So clear flags, show keyboard
// <https://stackoverflow.com/a/62767205/420412>
val window = dialog?.window
if (window != null) {
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return ComposeView(requireContext()).apply {
setContent {
MyComposable()
}
}
}
}