android 软键盘的弹出问题总结
16lz
2021-01-23
项目中用到软键盘的管理总结如下:
在开始进入页面时不弹出键盘
方法一:在包含EditText外层布局上添加
android:focusable="true"android:focusableInTouchMode="true"
抢在EditText获取焦点,即可
方法二:在onResume中加入这行代码
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
1,绑定软键盘到EditText:
edit.setFocusable(true);edit.setFocusableInTouchMode(true);edit.requestFocus();InputMethodManager inputManager = (InputMethodManager)edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(edit, 0);
editMsgView.setText("");editMsgView.clearFocus();//close InputMethodManagerInputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editMsgView.getWindowToken(), 0);EditText始终不弹出软件键盘
EditText edit=(EditText)findViewById(R.id.edit); edit.setInputType(InputType.TYPE_NULL);
还可以
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if(imm.isActive()){ //这里可以判断也可以不判断 imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0 ); }
1,在设置软键盘弹出属性界面加载后,软键盘不能弹出,不能弹出软键盘的主要原因是Android程序未将屏幕绘制完成,所以延迟一定时间,弹出软键盘。
方法一:
private Handler hander=new Handler(){public void handleMessage(android.os.Message msg) {edit.setFocusable(true);edit.setFocusableInTouchMode(true);edit.requestFocus();InputMethodManager inputManager = (InputMethodManager)edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(edit, 0);};};
@Overridepublic void onWindowFocusChanged(boolean hasWindowFocus) {if(visible){hander.sendEmptyMessageDelayed(0, 1000);}}
方法二:
Timer timer = new Timer();timer.schedule(new TimerTask() {@Overridepublic void run() {InputMethodManager m = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);}}, 300);
<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >
该Activity主窗口总是被调整屏幕的大小以便留出软键盘的空间
更多相关文章
- Android为什么会有65536的方法数量限制
- Android Studio ——Android 使用Pull方法解析XML文件的方法
- 关于安卓屏幕切换的过程
- 记录关于Gradle : Build Running的解决方法
- Android 开机震动的调用位置以及打开关闭方法
- Android事件触发EditText焦点和自动弹出键盘
- Android 软键盘的监听(监听高度,是否显示)
- Android 截取屏幕图片并保存
- Android中计算text文字大小的几个方法