Showing the on-screen keyboard for an activity
So I had an activity with some input fileds, including text ones. When the activity is displayed, Android set the focus to its EditText view. So far so good.
But the on-screen keyboard didn’t appear until I clicked in that EditText view. Hmm…. I was expecting it to show immediately, as soon as the activity was displayed.
Well, turns out, there is an attribute in the activity’s XML description that controls on-screen keyboad behaviour.
To display the on-screen keyboard right away, when the activity is shown, requires this:
<activity ..... android:windowSoftInputMode="stateVisible|adjustResize"> </activity>
The important value here is
stateVisible, whcih makes the keyboard show when the user navigates to this activity. The
adjustResize attribute specifies that the activity’s window should be resized if it’s necessary to make room for the keyboard.