屏幕显示时如何删除字段的自动对焦/键盘弹出?
我有一个屏幕,其中第一个字段是 EditText,它在启动时获得焦点,还弹出数字输入类型,这非常烦人,
我如何确保当活动启动时不会获得焦点,和/或者输入面板没有抬起?
I have a screen where the first field is an EditText, and it gains the focus at startup, also popups the numeric input type, which is very annoying
How can I make sure that when the activity is started the focus is not gained, and/or the input panel is not raised?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
或
在应用程序标签中设置清单文件中的活动属性,如下所示
or
set activity property in manifest file as below in the application tag
转到您的应用程序清单文件,并为您想要禁用自动键盘弹出窗口的活动编写此行。
go to your application manifest file, and write this line for that activity you want to disable auto keyboard pop-up.
以编程方式不显示键盘,但默认小部件仍接收焦点调用:
在
onResume()
中To programatically not have the keyboard displayed, but the default widget still recieve focus call:
in
onResume()
或者只需在
Manifest.xml
的 Activity 标记中添加android:windowSoftInputMode="stateHidden"
or simply add
android:windowSoftInputMode="stateHidden"
in Activity tag inManifest.xml
这通常是一团糟。我尝试的第一件事是尝试通过另一个视图来窃取焦点。您还必须具有 focusable 和 focusableInTouchMode。
This is usually a mess. The first thing I try is try to steal the focus with another view via . You also have to have the focusable and focusableInTouchMode.
有另一个视图来抓住焦点。默认情况下,当布局膨胀时,第一个可聚焦视图将获得焦点。您可以通过 XML 请求将焦点放在不同的视图上:
这适用于任何视图。
如果您想以编程方式执行此操作,可以使用
view.requestFocus()
。Have another view grab focus. By default, the first focusable View will get focus when a layout is inflated. You can request focus on a different View via XML:
This works for any View.
If you want to do it programmatically, you can use
view.requestFocus()
.将
android:windowSoftInputMode="stateHidden"
添加到清单中的 Activity 只会在您启动 Activity 时隐藏键盘,或者如 Google 所说要在用户按下后退按钮并从其他活动移回您的活动时也隐藏键盘,请使用
android:windowSoftInputMode="stateAlwaysHidden"
Adding
android:windowSoftInputMode="stateHidden"
to your Activity in manifest only hides the keyboard when you are launching the activity, or as Google saysTo hide the keyboard also when user presses the back button and moves back to your activity from some other activity, use
android:windowSoftInputMode="stateAlwaysHidden"
没有尝试过这个,我也没有靠近我的编程计算机,但我怀疑以编程方式将焦点发送到父视图或类似性质的东西可以做到这一点 - 这更可能是一种解决方法而不是解决方案,但再次无法测试它一个想法
have not tried this nor am i near my programming computer, but I would suspect programmatically sending focus to the parent view or something of that nature could do the trick - thats more likely a workaround than a solution, but again not able to test it just a thought