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

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

 

效果图如下:

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

 

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);

 

相关文章:

  • 2022-12-23
  • 2021-11-04
  • 2021-12-03
  • 2021-05-05
  • 2022-01-14
  • 2021-12-31
  • 2021-11-28
  • 2021-11-05
猜你喜欢
  • 2022-03-08
  • 2021-10-06
  • 2021-12-19
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
相关资源
相似解决方案