现在的位置: 首页 > 综合 > 正文

Android 手动显示和隐藏软键盘

2013年04月08日 ⁄ 综合 ⁄ 共 1003字 ⁄ 字号 评论关闭

1、方法一(如果输入法在窗口上已经显示,则隐藏,反之则显示)

[java] view
plain
copy

  1. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
  2. imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);  

 

2、方法二(view为接受软键盘输入的视图,SHOW_FORCED表示强制显示)

[java] view
plain
copy

  1. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
  2. imm.showSoftInput(view,InputMethodManager.SHOW_FORCED);  

[java] view
plain
copy

  1. imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘  


3、调用隐藏系统默认的输入法

[java] view
plain
copy

  1. ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);  (WidgetSearchActivity是当前的Activity)  


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

[java] view
plain
copy

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






  3. 转:http://blog.csdn.net/h7870181/article/details/8332991

抱歉!评论已关闭.