屏幕显示时如何删除字段的自动对焦/键盘弹出?

发布于 2024-09-02 14:10:11 字数 98 浏览 9 评论 0原文

我有一个屏幕,其中第一个字段是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

陌生 2024-09-09 14:10:11
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);

在应用程序标签中设置清单文件中的活动属性,如下所示

android:windowSoftInputMode="stateHidden"
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);

or

set activity property in manifest file as below in the application tag

android:windowSoftInputMode="stateHidden"
当爱已成负担 2024-09-09 14:10:11

转到您的应用程序清单文件,并为您想要禁用自动键盘弹出窗口的活动编写此行。

android:windowSoftInputMode="stateHidden"

go to your application manifest file, and write this line for that activity you want to disable auto keyboard pop-up.

android:windowSoftInputMode="stateHidden"
深海不蓝 2024-09-09 14:10:11

以编程方式不显示键盘,但默认小部件仍接收焦点调用:

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

onResume()

To programatically not have the keyboard displayed, but the default widget still recieve focus call:

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

in onResume()

明明#如月 2024-09-09 14:10:11
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

onCreate()中调用上述方法。除非用户通过点击或单击选择EditText,否则它会阻止softKeyboard显示。

或者只需在 Manifest.xml 的 Activity 标记中添加 android:windowSoftInputMode="stateHidden"

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

call the above method inside onCreate().It prevent softKeyboard to show unless user select EditText by tapping or clicking.

or simply add android:windowSoftInputMode="stateHidden" in Activity tag in Manifest.xml

垂暮老矣 2024-09-09 14:10:11

这通常是一团糟。我尝试的第一件事是尝试通过另一个视图来窃取焦点。您还必须具有 focusable 和 focusableInTouchMode。

<TextView
  ...
  android:focusable="true"
  android:focusableInTouchMode="true">

    <requestFocus/>
</TextView>

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.

<TextView
  ...
  android:focusable="true"
  android:focusableInTouchMode="true">

    <requestFocus/>
</TextView>
对你的占有欲 2024-09-09 14:10:11

有另一个视图来抓住焦点。默认情况下,当布局膨胀时,第一个可聚焦视图将获得焦点。您可以通过 XML 请求将焦点放在不同的视图上:

<TextView
    android:layout_width="wrap_parent"
    android:layout_height="wrap_content"
    android:text="Some other view">

    <requestFocus />
</TextView>

这适用于任何视图。

如果您想以编程方式执行此操作,可以使用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:

<TextView
    android:layout_width="wrap_parent"
    android:layout_height="wrap_content"
    android:text="Some other view">

    <requestFocus />
</TextView>

This works for any View.

If you want to do it programmatically, you can use view.requestFocus().

長街聽風 2024-09-09 14:10:11

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 says

When the user affirmatively navigates forward to the activity, rather
than backs into it because of leaving another activity

To hide the keyboard also when user presses the back button and moves back to your activity from some other activity, use android:windowSoftInputMode="stateAlwaysHidden"

眼眸印温柔 2024-09-09 14:10:11
if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED)
{
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED)
{
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
煞人兵器 2024-09-09 14:10:11

没有尝试过这个,我也没有靠近我的编程计算机,但我怀疑以编程方式将焦点发送到父视图或类似性质的东西可以做到这一点 - 这更可能是一种解决方法而不是解决方案,但再次无法测试它一个想法

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文