android实现回车键的监听
16lz
2021-12-04
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; } });
更多相关文章
- EditText
- android计算器布局(TableLayout)
- android ndk 入门 - 一个简单的ndk工程
- Delphi XE5 for android 调用Java类库必看的文件
- android带图片的AlertDialog和文件管理器(代码)
- android的文件操作
- android 自定义View中获取系统属性
- Android淘宝好评星级进度条RatingBar原来可以这么玩
- Android布局属性详解