关闭虚拟键盘上的按键preSS [英] Close virtual keyboard on button press

查看:359
本文介绍了关闭虚拟键盘上的按键preSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动的EditText ,一个按钮和一个的ListView 。其目的是要键入的EditText ,$ P $搜索屏幕PSS按钮并在搜索结果填充此列表。

这是一切工作的很好,但虚拟键盘行为奇怪。

如果我点击的EditText ,我得到的虚拟键盘。如果我点击虚拟键盘上的完成按钮,它就会消失。但是,如果我点击我的搜索按钮,点击虚拟键盘上的完成之前,虚拟键盘保持,我无法摆脱它。点击完成按钮不会关闭键盘。它改变了从完成完成按钮,一个箭头,仍然可见。

感谢您的帮助

解决方案

  mMyTextView.setOnEditorActionListener(新TextView.OnEditorActionListener(){
    公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
        如果(actionId == EditorInfo.IME_ACTION_SEARCH){
            //隐藏虚拟键盘
            InputMethodManager IMM =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(m_txtSearchText.getWindowToken(),
                                      InputMethodManager.RESULT_UNCHANGED_SHOWN);
            返回true;
        }
        返回false;
    }
});
 

I have an Activity with an EditText, a button and a ListView. The purpose is to type a search screen in the EditText, press the button and have the search results populate this list.

This is all working perfectly, but the virtual keyboard is behaving strange.

If I click the EditText, I get the virtual keyboard. If I click the "Done" button on the virtual keyboard, it goes away. However, if I click my search button before clicking "Done" on the virtual keyboard, the virtual keyboard stays and I can't get rid of it. Clicking the "Done" button does not close the keyboard. It changes the "Done" button from "Done" to an arrow and remains visible.

Thanks for your help

解决方案

mMyTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            // hide virtual keyboard
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(m_txtSearchText.getWindowToken(), 
                                      InputMethodManager.RESULT_UNCHANGED_SHOWN);
            return true;
        }
        return false;
    }
});

这篇关于关闭虚拟键盘上的按键preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆