Automatic popping up keyboard on start Activity
Solution 1
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
.
Solution 2
You can add this to your Android Manifest activity:
android:windowSoftInputMode="stateHidden|adjustResize"
Solution 3
I have several implementations described here, but now i have added into the AndroidManifest.xml
for my Activity
the property:
android:windowSoftInputMode="stateAlwaysHidden"
I think this is the easy way even if you are using fragments
.
"stateAlwaysHidden" The soft keyboard is always hidden when the activity's main window has input focus.
Solution 4
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 :)
Solution 5
Use this in your Activity's code:
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
Related videos on Youtube
Galip
Updated on January 01, 2021Comments
-
Galip over 3 years
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 the virtual keyboard.
How can I prevent this?
-
Android Help over 7 yearsCheck my answer on this question stackoverflow.com/questions/39593324/…
-
AhmadUllah Ahmad almost 5 yearsWhen My App is Launch (open) and if edit text view is Available so, keyboard is Automatic (show) enable. How to sole this problem click here easycomacademy.com/…
-
-
Luke about 13 yearsThis fixed my issue as well. I added this to the RelativeLayout tag for my activity. Thank you!
-
Jerry Brady about 13 yearsInterestingly enough, it didn't work when I added the above to a ScrollView, but it did work for a LinearLayout
-
David Doria over 10 yearsThis did not work for me - the keyboard still popped up when I start my activity.
-
David Doria over 10 yearsI did this but they keyboard still pops up and the focus is with the editText.
-
Utsav Gupta almost 10 yearsI think you have to put it on topmost layout
-
crowmagnumb almost 10 yearsSo I guess this works because you are telling the layout itself that it can have focus? Otherwise it assumes that it needs to give focus to the first control on the form? Oddly enough, I was getting the keyboard even if all the controls on my form were disabled. Fixed now. Thank you!
-
iversoncru about 9 yearsthis worked for me with both a ScrollView and a RelativeLayout.
-
Pelpotronic about 9 yearsIt's not that great for fragments, as you are associating the "hidden state" with the activity that will contain all your fragments, meaning that any fragment you want to display in the activity will be affected by the property (not on a "per fragment" basis).
-
Arthez over 8 yearsIt doesnt work for my top level scrollview, I suggest to use Mobile Bloke's answer, so far works for me everytime (in android manifest activity android:windowSoftInputMode="stateHidden|adjustResize")
-
dazza5000 about 8 yearsThank you - like mentioned earlier, this didnt' work on a scrollview, but worked on a linearlayout
-
Android Help over 7 yearsCheck my answer on this question stackoverflow.com/questions/39593324/…
-
Renato over 7 yearsIt's important to note that this solution creates accessibility problems (a view that should not be focusable being marked as having focus) and could have unintended consequences.
-
Sreelal S about 7 yearsusing fragment ..this code work to hide keyboard ...when a fragment open avoid the focus on edittext field keyboard ...
-
Faisal about 7 yearsIt works for me, thank you.. I put this code on <LinearLayout />
-
ArtiomLK almost 7 yearsThis works, however if you have an image background and are worried about your soft Keyboard shrinking such image background, use
android:windowSoftInputMode="stateHidden|adjustPan"
-
jk7 over 6 yearsThe question was how to prevent the keyboard from opening.
-
Sujeet about 4 yearsYou can check this link, It'll work: stackoverflow.com/questions/18977187/…
-
Sujeet about 4 yearsIf you are facing the issue in activities, You can check this link, It'll work: stackoverflow.com/questions/18977187/…
-
Usama Abdulrehman almost 4 yearsYou need to provide any limitations, assumptions or simplifications in your answer. See more details on how to answer at this link: stackoverflow.com/help/how-to-answer