EditText的imeOptions属性的使用

android:imeOptions的值有actionGo、 actionSend 、actionSearch、actionDone等。

它在Java中为EditorInfo.IME_ACTION_XXX

editText.setOnEditorActionListener,如:

  1. EditText editText = (EditText) contentView.findViewById(R.id.editText);  
  2.         editText.setOnEditorActionListener(new OnEditorActionListener() {  
  3.             @Override  
  4.             public boolean onEditorAction(TextView v, int actionId,  
  5.                     KeyEvent event) {  
  6.                 if (actionId == EditorInfo.IME_ACTION_SEARCH) {  
  7.                     Toast.makeText(getActivity(), "",Toast.LENGTH_SHORT).show();  
  8.                 }  
  9.   
  10.                 return false;  
  11.             }  
  12.         }); 

  13. 设置完后,却发现点击输入框,输入法键盘完全没变化,还是回车键

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

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

    1 将singleLine设置为true

    2 将inputType设置为text ,如:

  1. <EditText  
  2.       android:id="@+id/editText"  
  3.       android:layout_width="200dp"  
  4.       android:layout_height="wrap_content"  
  5.       android:imeOptions="actionSearch"  
  6.       android:singleLine="true"  
  7.       android:inputType="text"  
  8.    /> 

java代码设置,如:

  1. editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);  
  2. editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);  
  3. editText.setSingleLine(true); 



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值