当键盘处于活动状态然后在任何地方触摸屏时,请关闭键盘 [英] When keyboard active then touch screen anywhere, close keyboard

查看:136
本文介绍了当键盘处于活动状态然后在任何地方触摸屏时,请关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我无法使用正确的单词来找到所需的代码,因为我认为这是可行的.

I think I'm unable to use the correct words to find my desired code for this as I think this is doable.

我只是想从android关闭键盘视图,如果我按了按键以外的任何其他键. (实际上是在键盘上方...)

I simply want to close the keyboard view from android, if I press anywhere else than on the keys. (above the keyboard actually...)

例如当我进入EditView时,请完成编辑.

E.g. when I'm in an EditView, done editting.

推荐答案

EditText myEditText = (EditText) findViewById(R.id.myEditText); 
myEditText.setOnEditorActionListener(onEditorActionListener);

protected OnEditorActionListener onEditorActionListener = new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            resetTimeout();
            InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            v.clearFocus();
        }

        return false;
    }
};

这篇关于当键盘处于活动状态然后在任何地方触摸屏时,请关闭键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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