在EditText中开启软键盘的"Done"按钮

整理自:http://hi.baidu.com/doyee/blog/item/e2a8481628ebed4521a4e948.html
在EditText中,可以使用setImeOptions()方法来来开启软键盘的"Done"按钮。
示例代码如下: editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
界面如下:
在EditText中开启软键盘的Done按钮 - hubingforever - 民主与科学
  按下" Done "按钮的默认行为是关闭软键盘,但是我们可以通过 EditText setOnEditorActionListener() 方法来设置 OnEditorActionListener 以便添加自己的行为.
捕获Android文本输入框的软键盘完成(Done)按键消息:
  1. editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {  
  2.   
  3.     @Override  
  4.     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {  
  5.         if (actionId == EditorInfo.IME_ACTION_DONE) {  
  6.             InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);  
  7.             imm.hideSoftInputFromWindow(v.getWindowToken(), 0);  
  8.               
  9.             doSomething();  
  10.               
  11.             return true;    
  12.         }  
  13.         return false;  
  14.     }  
  15.       
  16. }); 
EditorInfo.IME_ACTION_DONE 可以和其他的标志一起组合使用来设置软键盘,比如:
editText.setImeOptions( EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE ); 
注意1 EditorInfo.IME_ACTION_DON E 只有对 android:singleLine="true" 的EditText有效。至少对HTC_A9191是这样的。
注意2:对于 EditorInfo.IME_ACTION_DON E ,有些输入法并不支持它,比如搜狐拼音输入法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值