免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2929 | 回复: 1
打印 上一主题 下一主题

EditText中关闭或者隐藏输入法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-14 19:20 |只看该作者 |倒序浏览
EditText中关闭或者隐藏输入法













1、EditText有焦点(focusable为true)阻止输入法弹出



Java代码
  1. 1.editText=(EditText)findViewById(R.id.txtBody);  
  2. 2.  
  3. 3.        editText.setOnTouchListener(new OnTouchListener() {               
  4. 4.  
  5. 5.            public boolean onTouch(View v, MotionEvent event) {   
  6. 6.  
  7. 7.                editText.setInputType(InputType.TYPE_NULL); // 关闭软键盘        
  8. 8.  
  9. 9.                return false;  
  10. 10.  
  11. 11.            }  
  12. 12.  
  13. 13.        });   
复制代码
2、当EidtText无焦点(focusable=false)时阻止输入法弹出  



Java代码
  1. 1.InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);      
  2. 2.  
  3. 3.       imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);   
复制代码
3、显示输入法



Java代码
  1. 1.InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);      
  2. 2.imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示));  
复制代码
4、隐藏输入法



Java代码
  1. 1.((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);  (WidgetSearchActivity是当前的Activity)   
复制代码
5、获取输入法状态



Java代码
  1. 1.InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
  2. 2.boolean isOpen=imm.isActive();  
  3. 3.isOpen若返回true,则表示输入法打开  
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-12-20 14:50 |只看该作者
学习鸟
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP