Android软键盘中的知识要点

来源:互联网 发布:excel2016数据记录单 编辑:程序博客网 时间:2024/06/10 17:34



android:imeOptions的值有actionGo、 actionSend 、actionSearch、actionDone等,这些意思都很明显

actionNone : 回车键,按下后光标到下一行
actionGo : Go,
actionSearch : 放大镜
actionSend : Send
actionNext : Next
actionDone : Done,确定/完成,隐藏软键盘,即使不是最后一个文本输入框


然而当我们设置这一切后,却发现点击输入框,输入法键盘完全没变化,还是回车键

这并不是上面的属性和方法无效,而是我们还需要设置别的属性来使它们生效

经过试验 设置下面两个属性中的一个即可使这个属性生效(应该还有其他的属性也可以,没去试验)

1 将singleLine设置为true

2 将inputType设置为text

 

android:singleline="true"

android:inputType="text"

android:imeoptions="actionSearch"



Android 手动显示和隐藏软键盘、

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

[java] view plain copy print?
  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 print?
  1. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
  2. imm.showSoftInput(view,InputMethodManager.SHOW_FORCED);  
[java] view plain copy print?
  1. imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘  


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

[java] view plain copy print?
  1. ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);  (WidgetSearchActivity是当前的Activity)  


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

[java] view plain copy print?
  1. InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
  2. boolean isOpen=imm.isActive();//isOpen若返回true,则表示输入法打开