解决Dialog 消失,输入法不消失的问题

前言:今天遇到一个奇怪的问题,Activity 里面弹出一个 dialog , 这个dialog里面有EditText 。

       问题:当 dialog 里面的输入法出现的时候,此时让diolog 消失,输入法不消失。

效果图如下:

         

dialog 创建方法:

  final AlertDialog.Builder builder = new AlertDialog.Builder(this);
  final AlertDialog dialog = builder.create() ;

1、使用下面的代码没有效果

 /**
     * 隐藏软键盘
     */
    void hideInput () {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if(inputMethodManager.isActive()){
            inputMethodManager.hideSoftInputFromWindow( this.getCurrentFocus().getWindowToken(), 0);
        }
    }

  

2、解决方法    

 //隐藏输入法
  InputMethodManager manager= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  manager.hideSoftInputFromWindow( dialog.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
原文地址:https://www.cnblogs.com/zhaoyanjun/p/4740375.html