简体   繁体   中英

how do you make it so the Android keyboard doesnt open up when the user opens up my app?

你能做到吗,所以当你打开应用程序时,只有当你点击其中一个editText时,屏幕上的键盘才会打开吗?

In order to hide the virtual keyboard, you can use the InputMethodManager like this (you can put it in the onCreate() method of your landing activity) :

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

Add the following code in onCreate method of your activity:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

It did the trick for me :)

在AndroidManifest.xml中设置android:configChanges =“ keyboardHidden”

it is up to your requirement. For suppose if you want to hide the keyboard every time the user opens your activity, then you can add android:windowSoftInputMode="stateAlwaysHidden" in your android manifest for your activity. If you want it dynamically then you can make change whenever event to close the keyboard occurs using

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

Use this as reference whenever you want

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM