Home > android, ui > Showing the on-screen keyboard for an activity

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.

Advertisements
Categories: android, ui
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s