简体   繁体   English

如何使用户打开我的应用程序时Android键盘不会打开?

[英]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 (您可以将其放在登陆活动的onCreate()方法中):

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

Add the following code in onCreate method of your activity: 在您的活动的onCreate方法中添加以下代码:

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. 假设您想在用户每次打开活动时都隐藏键盘,则可以在Android清单中为活动添加android:windowSoftInputMode="stateAlwaysHidden" 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 使用 ,每当你想作为参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android - 点击通知打开我的主要活动,如何让它打开其他东西 - Android - Click on notification opens up my main activity, how do I make it open up something else 如何在Android中打开键盘时向上移动我的小部件 - How to move my widget up when keyboard open in android 在 Android Studio 上运行应用程序,模拟器打开,但不显示应用程序 - Running App on Android Studio, Emulator opens up, but doesnt show app 如何备份 android 应用程序? - How do you back up an android app? 您如何制作没有UI的应用程序,所以当您打开它时,它将运行一些代码 - How do you make an app with no UI so when you open it, it runs some code 使用Facebook注册后第二次打开我的android应用时,如何从第二次获取更新的用户数据? - How to get updated user data from second time when when open my android app second time after sign up with Facebook? 打开键盘后,Android会向上移动页脚 - Android move footer up when keyboard is open 当键盘打开的webview在android中向上移动? - when keyboard open webview move to up in android? Android:打开键盘时会出现Tablayout - Android: Tablayout comes up when keyboard open 如何使用Android上的键盘使元素向上移动(HTML 5应用程序) - How to make an element move up with the keyboard on android (HTML 5 app)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM