java dialog 不显示_解决Dialog 消失,输入法不消失的问题

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

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

效果图如下:

16adeeaaa41d3c3984d09d8150eae1df.png

1cea51bc9b33163787868e6257b236da.png

8a5dd24c5a49d068e936bce574c74c64.png

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/category/684868.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值