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?
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.
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.
What worked best for me is in Android Manifest for activity B adding
android:windowSoftInputMode="stateVisible"
Hope that helps for you as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With