隐藏键盘,当用户点击其他地方的android屏幕上 [英] hide keyboard when user taps anywhere else on the screen in android

查看:103
本文介绍了隐藏键盘,当用户点击其他地方的android屏幕上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要隐藏softkeypad在机器人上时,除EDITTEXT其他任何地方的用户点击。有很多帮助,为iPhone而不是Android版。我想这code,但它不工作:(

I need to hide the softkeypad in android when user click on anywhere other than a Edittext. There are many help for iphone but not for android. I tried this code but its not working :(

final RelativeLayout base = (RelativeLayout) findViewById(R.id.RelativeLayout1);

    findViewById(R.id.base).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(base.getWindowToken(), 0);

        }
    });

在此先感谢!

Thanks in advance !

推荐答案

您可以使用的onTouchEvent()隐藏 Softkeyboard

@Override
    public boolean onTouchEvent(MotionEvent event) {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.
                                                        INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        return true;
    }

这篇关于隐藏键盘,当用户点击其他地方的android屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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