I have a quite simple Layout with an EditText and a button. The problem is the keyboard appears immediately after the activity is started and the EditText gets the focus. I removed the </requestFocus>
from XML and I also don't do that in code. How can I prevent that behavior of EditText so the keyboard only appears after the used taps the editText?
Asked
Active
Viewed 7,651 times
7

Droidman
- 11,485
- 17
- 93
- 141
-
Are you sure you removed all requestFocus? It shouldn't open your keyboard if you don't request it anywhere. Maybe posting your code could help. – Stefan de Bruijn Jan 09 '13 at 15:38
-
do you still have any issue regarding it ?? – Bajirao Shinde Mar 02 '16 at 10:33
-
2Adding `android:focusableInTouchMode="true"` on my **parent layout** works for me. – Marcelo Gracietti May 12 '17 at 15:06
3 Answers
5
In your manifest.xml
file, under the activity tag, place this:
android:windowSoftInputMode="stateHidden"

yedpodtrzitko
- 9,035
- 2
- 40
- 42

Gridtestmail
- 1,459
- 9
- 10
-
1thanks, that solved the issue. Can you tell me if that code can have any side effects which I should keep in mind? – Droidman Jan 09 '13 at 16:59
-
The answer below using `adjustNothing` is better. If you use `stateHidden`, then the keyboard will be closed when open on rotate. That is not usually desirable behavior. – Sky Kelsey May 05 '14 at 00:18
-
3
4
try this
In your AndroidManifest.xml
file write these lines
<activity
android:configChanges="keyboardHidden|orientation"
android:name=".YourActivityName"
android:windowSoftInputMode="stateHidden" />
i just added details..

Zar E Ahmer
- 33,936
- 20
- 234
- 300
3
From my POV a more elegant solution is:
In XML add these lines to the main layout:
<LinearLayout android:id="@+id/mainLayout" android:focusable="true" android:focusableInTouchMode="true" ... .../>
And In Java in onCreate():
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout); mainLayout.requestFocus();

Artyom Okun
- 939
- 1
- 8
- 14