android 软键盘回车变搜索_第1张图片


两种方法:

1.xml

android:imeOptions="actionSearch"


<EditText        android:id="@+id/et_search"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        android:ems="10"        android:imeOptions="actionSearch"        android:inputType="text" >        <requestFocus />    </EditText>



2.代码控制

et_search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);


完整代码

EditText et_search = (EditText) findViewById(R.id.et_search);et_search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);et_search.setOnEditorActionListener(new OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView arg0, int keyCode,KeyEvent arg2) {if (keyCode == EditorInfo.IME_ACTION_SEARCH) {// 先隐藏键盘((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);Toast.makeText(MainActivity.this, "YQY_Editor",Toast.LENGTH_SHORT).show();}return false;}});




复制去Google翻译 翻译结果 android:imeOptions="actionSearch"

更多相关文章

  1. 编写android拨打电话apk应用实例代码
  2. android 用代码编写linearlayout布局
  3. android延迟进入主界面和点击按钮进入主界面代码
  4. Android EditText输入框被键盘遮挡问题解决
  5. Android 架构解析及驱动 键盘篇
  6. Android键盘映射
  7. Android使用webview让服务器上的js调用java代码的方法
  8. android闹钟――原代码

随机推荐

  1. android软件音量控制
  2. 如何在android画分析图(例如 柱状图、趋势
  3. Android项目导出jar包的小技巧
  4. Windows平台下如何使用Android(安卓)NDK
  5. Android开机自启APK应用
  6. [Android]Android 颜色大全 colors.xml
  7. android linearlayout imageview置顶摆放
  8. 静默安装实现方法
  9. react native 修改Picker样式Android
  10. Android & Java规范