您的位置:首页 > 其它

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

2015-08-18 19:25 393 查看
前言:今天遇到一个奇怪的问题,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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: