1.在Layout文件中,给EditText文件添加属性android:imeOptions=""

属性值含义:

actionUnspecified:未指定

actionNone :没有动作

actionSearch: 搜索

actionSend: 发送

actionNext: 下一项

actionGo:去往

actionDone :完成

对应用到的常量:

EditorInfo.IME_ACTION_UNSPECIFIED

EditorInfo.IME_ACTION_NONE

EditorInfo.IME_ACTION_SEARCH

EditorInfo.IME_ACTION_SEND

EditorInfo.IME_ACTION_NEXT

EditorInfo.IME_ACTION_GO

EditorInfo.IME_ACTION_DONE

 

2.EditText添加监听器

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.版本高于2.3,EditText设置inputType为text或singleLine为true才会有效果

2.onEditorAction需返回true,不然方法会执行两次

更多相关文章

  1. FrameLayout的使用——android开发之xml布局文件
  2. android中将数据写入手机内存和sdcard中的文件
  3. android:installLocation这个属性
  4. android+spring boot 选择,上传,下载文件
  5. Eclipse下Android工程无法自动产生R文件解决

随机推荐

  1. android系统长按的定义
  2. AndroidMenifest.xml(Android清单文件)内
  3. Android官方资料--A/B System Updates
  4. Android调用摄像头闪退
  5. Android实现图片缩放与旋转
  6. 解读ExpandableListView源码样式
  7. android加密的即时通信软件 -服务器端
  8. 在 actionbar中使用 searchview
  9. android 写文件权限
  10. 初探 Ubuntu下android NDK