android实现回车键的监听
16lz
2021-01-23
1.布局文件中的edittext:设置属性
android:singleLine="true"android:imeOptions="actionSearch"
2.java文件中
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_UNSPECIFIED) { Toast.maketext(this,"你点击了回车",Toast.LENGTH_SHORT).show(); //隐藏软键盘 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0); } return false; } });
更多相关文章
- android用于打开各种文件的intent
- Android--取得布局中指定控件的宽高
- android计算器布局(TableLayout)
- Delphi XE5 for android 调用Java类库必看的文件
- android带图片的AlertDialog和文件管理器(代码)