android 软键盘隐藏 activity初始化时edittext聚焦
16lz
2021-01-23
在xml中某一个view上写上
android:focusable="true"
android:focusableInTouchMode="true"
这样edittext就不会再聚焦
让软键盘消失
在程序中加入以下代码时,软键盘会出现:
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN); 如果要让软键盘消失,则为以下代码: InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);很多应用中对于一个界面比如进入搜索界面或者修改信息等等情况,为了用户体验应该自动弹出软键盘而不是让用户主动点击输入框才弹出(因为用户进入该界面必然是为了更改信息)。具体实现这种效果如下: EditText editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); InputMethodManager inputManager = (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(editText, 0); 首先要对指定的输入框请求焦点。然后调用输入管理器弹出软键盘。
更多相关文章
- MT6573默认锁屏界面修改
- android中 检查网络连接状态的变化,无网络时跳转到设置界面
- Android中的界面布局之帧布局,相对布局
- Android界面开发推荐颜色
- Android 虚拟键盘弹出把底部view顶上去的解决办法
- Android开发实例之登录界面的实现
- Android空白处隐藏软键盘方案