EditText焦点控制及软键盘的隐藏显示
16lz
2021-01-26
EditText在使用中,默认情况下是自动获取焦点的,但是有很多情况下,我们不需要它弹出显示,这时候就需要我们根据不同场景来决定焦点的获取与否
显示:EditText是默认显示的,多个editText的情况下会按照顺序进行焦点的获取 在布局文件中设置
android:focusable="true" android:focusableInTouchMode="true"
在.java文件中
EditText.setFocusable(true);EditText.setFocusableInTouchMode(true);EditText.requestFocus();
隐藏:布局文件中将其父控件设置为:
android:focusable="true"android:focusableInTouchMode="true"
在.java文件中
Parent.setFocusable(true);Parent.setFocusableInTouchMode(true);
手动控制软键盘的显示与否
软键盘隐藏代码
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);imm.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);
软键盘显示代码:
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
仅此献给有需要的人!!!
更多相关文章
- Android(安卓)lint 自动检测并删除无用资源
- Android系统权限和root权限的获取以及应用权限列表
- 使用Jenkins自动打包android
- Android与Js调用
- 获取listview checkbox选择的值 android
- Android-内存映射mmap
- dex 转为 jar
- Android(安卓)ndk移植c库libpng
- android的ndk开发入门示例