Android程序打开和关闭输入法,this.getCurrentFocus()有时为空,

this.getCurrentFocus()

公司的一个测试机好像是华为的 8500

有物理键 上下左右的。

当输入帐号密码 使用上下键 到确定,这个时候 输入法隐藏了,,但是debugboolean isOpen=imm.isActive(); 这个返回true;

最后发现是

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

InputMethodManager.HIDE_NOT_ALWAYS);

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

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

一、打开输入法窗口:

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

// 接受软键盘输入的编辑文本或其它视图

imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

二、关闭出入法窗口

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

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

InputMethodManager.HIDE_NOT_ALWAYS);

//接受软键盘输入的编辑文本或其它视图

inputMethodManager

.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

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

InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

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

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);boolean isOpen=imm.isActive();isOpen若返回true,则表示输入法打开

正确的寒暄必须在短短一句话中明显地表露出你对他的关怀。

Android程序打开和关闭输入法,this.getCurrentFocus()有时为空,

相关文章:

你感兴趣的文章:

标签云: