Custom AlertDialog, EditText, setSoftInputMode, and Disappearing View

What’s causing views below EditText in a custom AlertDialog disappearing and how to solve it

There is a dialog with custom view containing EditText as shown below in Typing Hero.
notion image
 
You would call window?.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE) so user can access the keyboard right away as it shows up.
However, calling window?.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE) before dialog.show() can make the view below EditText not visible.
notion image
notion image
 
Apparently, setSoftInputMode eventually updates the view’s layout which is not yet visible.
notion image
notion image
 
To prevent that from happening, call dialog.show() before window?.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE).
 
Maybe it’s worth to mention that this is happening on physical device and NOT not on emulator.
Sen

Written by

Sen