为什么虚拟键盘没有消失?

发布于 2024-10-09 09:35:47 字数 215 浏览 0 评论 0原文

我有一个非常简单的屏幕,其中有几个 EditText 小部件和一个按钮。在模拟器中,当我单击 EditText 小部件时,会出现一个虚拟键盘。然而,我似乎无法摆脱它。单击屏幕上的空白区域不会使其消失。只需单击虚拟返回键或硬件返回按钮即可使其消失。

我手边没有真正的 Android 手机,所以这只是模拟器的事情还是在实际设备上会这样。如果是,当我单击表单上的其他位置时,我该怎么做才能使虚拟键盘消失?

I have a pretty simple screen with a couple of EditText widgets and a button. In the emulator, when I click on the EditText widget, a virtual keyboard comes up. However, I can't seem to get rid of it. Clicking on an empty space on the screen does not make it go away. Only clicking the virtual Return key or the hardware Back button makes it disappear.

I don't have a real Android phone handy, so is this an emulator only thing or will it be like this on the actual device. If it is, what can I do to make the virtual keyboard go away, when I click elsewhere on the form?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

旧梦荧光笔 2024-10-16 09:35:47

单击后退按钮。他们敲键盘是一项活动。单击屏幕的随机区域时,没有一种简单的方法可以移除键盘。

Click the back button. They keyboard is an activity. There's not an easy way to remove the keyboard when clicking on a random area of the screen.

青朷 2024-10-16 09:35:47

AngryHacker,我建议您参考这篇文章 如何关闭/隐藏 android软键盘

希望这有帮助。

AngryHacker , I woud refer you to this post how to close/hide the android soft keyboard.

Hope this helps.

苏大泽ㄣ 2024-10-16 09:35:47

我认为在模拟器中你可以按 Escape 来隐藏键盘。在真实设备上,键盘上有一个隐藏按钮,或者您可以按用户界面中的其他位置。无论如何,这就是我的 HTC Desire S 上的工作原理。

I think in the emulator you can press Escape to hide the keyboard. On a real device there is a hide button on the keyboard or you can press elsewhere in the ui. That's how it works on my HTC Desire S anyway.

救赎№ 2024-10-16 09:35:47

我遇到了这个问题并解决了它。这个问题与我的项目中的 InputMethodManager.SHOW_FORCED 值有关。当我使用 SHOW_FORCED 打开键盘时,当我尝试关闭键盘时,键盘没有关闭。

例如:

activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_FORCED);

如果您使用上述方式打开键盘,您可以尝试将 SHOW_FORCED 值更改为 SHOW_IMPLICIT

例如:

activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);

I lived this problem and i resolved it. This problem is about InputMethodManager.SHOW_FORCED value in my project. When i open keypad using SHOW_FORCEDthen when i try to close keypad, keypad was not closing.

For Example :

activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_FORCED);

If you use above way to open keypad, you may try to change SHOW_FORCED value with SHOW_IMPLICIT value

For Example :

activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
捶死心动 2024-10-16 09:35:47

我的 Galaxy S2 运行的是 Andriod 2.3.6。
我在登录网站时遇到输入所需文本后键盘无法移开的问题。我发现按下硬件返回按钮确实可以消除虚拟键盘的干扰。但有时它会使网络浏览器返回一页。这令人沮丧,因为这样我就必须重新输入我连接的任何网站的登录信息。希望 Android 4.x 已经解决了其中一些小问题。

I have the Galaxy S2 which is running Andriod 2.3.6.
I was having issues with the keyboard not moving out of the way after entering the needed text when logging into websites. I found that hitting the hardware return button does take the virtual keyboard out of the way. But occassionally it will take the web browser back one page. Which is frustrating because then I have to re-enter the log in info for whatever web site I'm connecting too. Hopefully Android 4.x has solved some of these glitchy issues.

苏大泽ㄣ 2024-10-16 09:35:47

您可以通过执行以下步骤来实现此目的:

  1. 通过添加以下属性使父视图(活动的内容视图)可点击且可聚焦

     android:clickable="true" 
        android:focusableInTouchMode="true" 
    
  2. 实现 hideKeyboard() 方法

     public void hideKeyboard(View view) {
            InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
        }
    
  3. 最后,设置 edittext 的 onFocusChangeListener。

     edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @覆盖
            公共无效onFocusChange(视图v,布尔hasFocus){
                如果(!hasFocus){
                    隐藏键盘(v);
                }
            }
        });
    

来源

You can achieve this by doing the following steps:

  1. Make the parent view(content view of your activity) clickable and focusable by adding the following attributes

        android:clickable="true" 
        android:focusableInTouchMode="true" 
    
  2. Implement a hideKeyboard() method

        public void hideKeyboard(View view) {
            InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
        }
    
  3. Lastly, set the onFocusChangeListener of your edittext.

        edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    hideKeyboard(v);
                }
            }
        });
    

Source

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