方法一:在你的activity中的oncreate中setContentView以前写上这个代码html
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
方法二:在项目的AndroidManifest.xml文件中界面对应的<activity>里加入,这样会让屏幕总体上移。android
android:windowSoftInputMode="stateVisible|adjustResize"
若是加上的是这样键盘就会覆盖屏幕。ide
android:windowSoftInputMode="adjustPan"
方法三:把顶级的layout替换成ScrollView,或者说在顶级的Layout上面再加一层ScrollView的封装。这样就会把软键盘和输入框一块儿滚动了,软键盘会一直处于底部。this
// 点击空白区域 自动隐藏软键盘 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); }
//此方法只是关闭软键盘 能够在finish以前调用一下 xml
//此方法只是关闭软键盘 能够在finish以前调用一下 private void hintKbTwo() { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); if(imm.isActive()&&getCurrentFocus()!=null){ if (getCurrentFocus().getWindowToken()!=null) { imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }
//此方法,若是显示则隐藏,若是隐藏则显示 private void hintKbOne() { InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); // 获得InputMethodManager的实例 if (imm.isActive()) { // 若是开启 imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); } }