简体   繁体   English

单击外部EditText后如何隐藏android上的软键盘? 在片段中

[英]How to hide soft keyboard on android after clicking outside EditText? in fragment

i want to hide keyboard when user torches outside the Edit text but is not from activity but from fragment please any possible solution当用户在编辑文本之外但不是来自活动而是来自片段时我想隐藏键盘请任何可能的解决方案

Try to get EditTesxt focus status with setOnFocusChangeListener and if it's not focused hide the keyboard:尝试使用setOnFocusChangeListener获取 EditTesxt 焦点状态,如果没有焦点,则隐藏键盘:

    editText.setOnFocusChangeListener((v, hasFocus) -> {
        if (!hasFocus) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM