I got a relative simple question. I have an activity with a lot of EditText\'s in them. When I open the activity it automatically focusses to the first EditText and displays
I have several implementations described here, but now i have added into the AndroidManifest.xml
for my Activity
the property:
android:windowSoftInputMode="stateAlwaysHidden"
fragments
."stateAlwaysHidden" The soft keyboard is always hidden when the activity's main window has input focus.
android:windowSoftInputMode="stateHidden|adjustResize"
Working fine
If you have another view on your activity like a ListView
, you can also do:
ListView.requestFocus();
in your onResume() to grab focus from the editText
.
I know this question has been answered but just providing an alternative solution that worked for me :)
Use this attributes in your layout tag in XML file:
android:focusable="true"
android:focusableInTouchMode="true"
As reported by other members in comments it doesn't works on ScrollView
therefore you need to add these attributes to the main child of ScrollView
.
Interestingly, this documentation https://developer.android.com/training/keyboard-input/visibility.html states that when an activity starts and focus is given to a text field, the soft keyboard is not shown (and then goes on to show you how to have the keyboard shown if you want to with some code).
On my Samsung Galaxy S5, this is how my app (with no manifest entry or specific code) works -- no soft keyboard. However on a Lollipop AVD, a soft keyboard is shown -- contravening the doc given above.
If you get this behavior when testing in an AVD, you might want to test on a real device to see what happens.
This occurs when your EditText automatically gets Focus as when you activity starts. So one easy and stable way to fix this, is simply to set the initial focus to any other view, such as a Button etc.
You can do this in your layout XML, no code required..