软键盘的关闭和显示

this.getCurrentFocus() 

Boolean isOpen=imm.isActive(); 这个返回true;

最后发现是

inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(),

InputMethodManager.HIDE_NOT_ALWAYS);

中OpeListActivity.this.getCurrentFocus()  这个为空,所以报错。

 没想到其他解决方法。就try catch;,,至少不报错了。

一、打开输入法窗口:

<span style="font-size:14px;">InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
// 接受软键盘输入的编辑文本或其它视图
</span><pre name="code" class="java" style="color: rgb(51, 51, 51); line-height: 26px;"><span style="font-size:14px;">inputMethodManager<span style="font-family: Arial, Helvetica, sans-serif;">.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);</span></span>

 
 

二、关闭出入法窗口

<span style="font-size:14px;">InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);</span>
<span style="font-family: 'Microsoft YaHei'; color: rgb(51, 51, 51); line-height: 26px; background-color: rgb(255, 255, 255);"><span style="font-size:14px;">//接受软键盘输入的编辑文本或其它视图</span></span>
<span style="color: rgb(51, 51, 51); line-height: 26px; font-family: Arial, Helvetica, sans-serif;"><span style="font-size:14px;">inputMethodManager.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);</span></span>

三、如果输入法打开则关闭,如果没打开则打开

<span style="font-size:14px;">InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);</span>

四、获取输入法打开的状态

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();

isOpen若返回true,则表示输入法打开


 软键盘显示的原理软件盘的本质是什么?软键盘其实是一个Dialog!

 InputMethodService为我们的输入法创建了一个Dialog,并且将该Dialog的Window的某些参数(如Gravity)进行了设置,使之能够在底部或者全屏显示。当我们点击输入框时,系统对活动主窗口进行调整,从而为输入法腾出相应的空间,然后将该Dialog显示在底部,或者全屏显示。


 转自:http://blog.csdn.net/zgf1991/article/details/7754972

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值