当前位置: 移动技术网 > IT编程>移动开发>Android > Android中EditText 设置 imeOptions 无效问题的解决方法

Android中EditText 设置 imeOptions 无效问题的解决方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

双色球预测neiba,人皮灯笼2,再世魔导txt

有时候我们需要在edittext  输出完之后 需要在键盘出现 右下角变成“go”或“前往 搜索时;通常我们需要设置android:imeoptions属性。android:imeoptions的值有actiongo、 actionsend 、actionsearch、actiondone等

但是今天我发现设置了无效  那是因为我设置了 android:maxlines="1"

解决方法 就是去掉 android:maxlines="1"  设置 android:singleline="true" 有必要还需要 inputtype设置为text

网上有一种监听点击回车 搜索的写法 这种写法 会执行两次  解决方法是

edittext.setoneditoractionlistener(new textview.oneditoractionlistener() { 
public boolean oneditoraction(textview v, int actionid,          keyevent event) {             
if (actionid==editorinfo.ime_action_send ||(event!=null&&event.getkeycode()== keyevent.keycode_enter)) 
{        
//do something;       
return true;       
}        
return false;      
}    
});

解决方法是 1  (ps 这种方法我感觉写法有点多余)

public boolean oneditoraction(textview v, int actionid, keyevent event) { 
    //以下方法防止两次发送请求 再判断动作 
    if (actionid == editorinfo.ime_action_send || 
        (event != null && event.getkeycode() == keyevent.keycode_enter)) { 
      switch (event.getaction()) { 
        case keyevent.action_up: 
          //发送请求 
          string keyword = et_search.gettext().tostring().trim(); 
          if (null == keyword) 
            keyword = ""; 
          dismisspopup(); 
          logutils.d("向服务器发送搜索请求:" + keyword); 
          //发起查询 
          searchbykeyword(keyword); 
          hidesoftinput(); 
          return true; 
        default: 
          return true; 
      } 
    } 
    return false; 
  } 

还有一种写法   直接监听actionid等于搜需要的时间即可

edittext edittext = (edittext) contentview.findviewbyid(r.id.edittext); 
    edittext.setoneditoractionlistener(new oneditoractionlistener() { 
      @override 
      public boolean oneditoraction(textview v, int actionid, 
          keyevent event) { 
        if (actionid == editorinfo.ime_action_search) { 
          toast.maketext(getactivity(), "1111111",toast.length_short).show(); 
        } 
        return false; 
      } 
    }); 

以上所述是小编给大家介绍的android中edittext 设置 imeoptions 无效问题的解决方法,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网