方法一:在你的activity中的oncreate中setContentView之前写上这个代码
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
方法二:在项目的AndroidManifest.xml文件中界面对应的<activity>里加入,这样会让屏幕整体上移。
android:windowSoftInputMode="stateVisible|adjustResize"
如果加上的是这样键盘就会覆盖屏幕。
android:windowSoftInputMode="adjustPan"
方法三:把顶级的layout替换成ScrollView,或者说在顶级的Layout上面再加一层ScrollView的封装。这样就会把软键盘和输入框一起滚动了,软键盘会一直处于底部。
点击空白区域,隐藏输入法软键盘
// 点击空白区域 自动隐藏软键盘 public boolean onTouchEvent(MotionEvent event) { if(null != this.getCurrentFocus()){ /** * 点击空白位置 隐藏软键盘 */ InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); return mInputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); } return super .onTouchEvent(event); }