Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show soft keyboard when Activity starts

I have 2 activities, A and B. When A starts, it checks for a condition and if true, it calls startActivityForResult() to start B. B only takes text input so it makes sense for the soft keyboard to automatically pop up when B start. When the activity starts, the EditText already has focus and it ready for input.

The problem is that the keyboard never shows up, even with windowSoftInputMode="stateAlwaysVisible" set in the manifest under the <activity> tag for B. I also tried with the value set to stateVisible. Since it doesn't show up automatically, I have to tap the EditText to make it show.

Anyone know what the solution might be?

like image 976
Al. Avatar asked Mar 17 '10 23:03

Al.


People also ask

How can I tell if my keyboard is open or soft?

Android provides no direct way to determine if the keyboard is open, so we have to get a little creative. The View class has a handy method called getWindowVisibleDisplayFrame from which we can retrieve a rectangle which contains the portion of the view visible to the user.

How do I show soft keyboard when Edittext is focused?

android:windowSoftInputMode="stateAlwaysVisible" -> in manifest File. edittext. requestFocus(); -> in code. This will open soft keyboard on which edit-text has request focus as activity appears.


1 Answers

What worked best for me is in Android Manifest for activity B adding

android:windowSoftInputMode="stateVisible"

Hope that helps for you as well.

like image 143
Leo Avatar answered Sep 19 '22 18:09

Leo