通过设置android:imeOptions来改变软键盘Enter键图标

转载自: http://blog.csdn.net/wf_zeng/article/details/9339431 


1.actionUnspecified 未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.

2.actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE

3.actionGo 去往,对应常量EditorInfo.IME_ACTION_GO 

4.actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH

5.actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND

6.actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT

7.actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE


android键盘中的enter键图标是可以用EditText的android:imeOptions标签变更的。

显示search图标需要设置为android:imeOptions="actionSearch"android:inputType="text"将键盘设置为文字输入布局

则键盘中search按钮正常出现

捕捉编辑框软键盘enter事件:

1)setOnKeyListener

2)OnEditorActionListener


实现android按下回车键便隐藏输入键盘,有两种方法:

1)如果布局是多个EditText,为每个EditText控件设置android:singleLine=”true”,弹出的软盘输入法中回车键为next,直到最后一个获取焦点后显示为Done,点击Done后,软盘输入键盘便隐藏。或者将EditText的imeOptions属性设置android:imeOptions=”actionDone”,则不管是不是最后一个EditText,点击回车键即隐藏输入法。

2)监听Enter的事件,编写Enter的事件响应。设置文本框的OnKeyListener,当keyCode ==KeyEvent.KEYCODE_ENTER的时候,表明Enter键被按下,就可以编写自己事件响应功能了

[java]  view plain copy print ?
  1. EditText password=(EditText)findViewById(R.id.password);  
  2.   
  3. password.setOnKeyListener(new OnKeyListener(){  
  4.   
  5. public boolean onKey(View v, int keyCode, KeyEvent event) {  
  6.   
  7. if(keyCode == KeyEvent.KEYCODE_ENTER){  
  8.   
  9. InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);  
  10.   
  11. if(imm.isActive()){  
  12.   
  13. imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0 );  
  14.   
  15. }  
  16.   
  17. return true;  
  18.   
  19. }  
  20.   
  21. return false;  
  22.   
  23. }  
  24.   
  25. });  


参见:

http://blog.csdn.net/liuxiit/article/details/6903884

http://fariytale.iteye.com/blog/1233625

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值