Reputation: 41
Hi I have some EditTexts and a button at the bottom of the view. Upon starting the activity, the first EditText will gain focus and a keyboard will pop up. I want to upon starting the activity, the focus will be on the button instead of the EditText and the keyboard should not pop up. I tried running:
button.requestFocus();
The EditText still have focus and pops up the keyboard. How can I resolve this? Thanks.
Upvotes: 1
Views: 6631
Reputation: 1284
Its trickier than it seems, but certainly possible. See here:
Stop EditText from gaining focus at Activity startup
Upvotes: 5
Reputation: 1730
Put android:windowSoftInputMode="stateHidden" to your Activity which contains EditText
<activity android:name=".YourActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
Upvotes: 2
Reputation: 2927
You can force hide the keyboard by calling this on the EditText view
InputMethodManager mgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(myView.getWindowToken(), 0);
Hope this helps,
-serkan
Upvotes: 1