键盘的展开和收起主要使用到类InputMethodManager:http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html

其大致方法如下:

1 public void hide_keyboard_from(Context context, View view) {2         InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);3         inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);4     }5     6 public void show_keyboard_from(Context context, View view) {7         InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);8         inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);9     }

在展开和收起方法调用的时候,都要求传入第二个参数。大致有以下四种:

1)HIDE_IMPLICIT_ONLY:indicate that the soft input window should only be hidden if it was not explicitly shown by the user.

2)HIDE_NOT_ALWAYS:to indicate that the soft input window should normally be hidden, unless it was originally shown withSHOW_FORCED

3)SHOW_FORCED:indicate that the user has forced the input method open (such as by long-pressing menu) so it should not be closed until they explicitly do so.

4)SHOW_IMPLICIT:indicate that this is an implicit request to show the input window, not as the result of a direct request by the user.

1)和2)是用于收起键盘的,3)和4)是用于展开键盘的。

如果用户是点击输入框弹出的键盘,则调用1)是无法隐藏的,系统此时判断使用户有意呼唤键盘的!调用2)则可以收起键盘;

如果用户是使用3)作为参数显示键盘的,则1)和2)都是无法隐藏键盘的,此时需要用参数0,强制隐藏一切键盘;

如果用户是使用4)作为参数显示键盘的,则1)和2)都是可以隐藏键盘的。

总结起来就是:Forced > explicit > implicit。

对于隐藏键盘,其中1)是属于implicit,2)是属于explicit,0则是属于force;

对于显示键盘,则4)是属于implicit,输入框呼出属于explicit,3)则是属于force;

只有隐藏的级别>=展开的级别,才能将键盘隐藏掉。

更多相关文章

  1. Android学习07-----事件处理(4)键盘事件和触摸事件
  2. TabHost随着输入法软键盘出现而上浮的问题
  3. 禁止Edittext弹出系统软键盘 的几种方法
  4. Android(安卓)PopupWindow 隐藏软键盘的方法
  5. android 学习五 设置应用程序全屏(没有状态栏和标题栏)
  6. Android(安卓)软键盘遮挡三种解决方案
  7. Android学习07-----事件处理(4)键盘事件和触摸事件
  8. EditText
  9. Android禁止EditText自动弹出软键盘的方法

随机推荐

  1. android 播放器开发准备工作
  2. Android(安卓)Studio 日期选择器和时间选
  3. android - 常用知识点以及代码片段(不断更
  4. Android5.0以太网流程源码情景分析
  5. MyCms v3.4,自媒体博客+购物商城系统
  6. 初学者怎么手部上色?人物手部上色技法!
  7. Ubuntu中fcitx安装失败问题,及软件换源问
  8. 使用 Laravel Filament 极速搭建美观大方
  9. 何学习场景原画?场景的设计技巧学习
  10. 怎么画人物?动漫人物绘画步骤!