android 软键盘回车变搜索
16lz
2021-01-23
两种方法:
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;}});
更多相关文章
- 编写android拨打电话apk应用实例代码
- android 用代码编写linearlayout布局
- android延迟进入主界面和点击按钮进入主界面代码
- Android EditText输入框被键盘遮挡问题解决
- Android 架构解析及驱动 键盘篇
- Android键盘映射
- Android使用webview让服务器上的js调用java代码的方法
- android闹钟――原代码