1,设置键盘不占空间的方法:
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustNothing"
>
设置为这个 让推上去的内容居中显示,特别注意,不能设置状态栏颜色,否则无效
android:windowSoftInputMode="adjustResize"
2,关闭软键盘的方法:
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm.isActive()&&getActivity().getCurrentFocus()!=null){
if (getActivity().getCurrentFocus().getWindowToken()!=null) {
Log.i("ok","有软键盘!");
imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
如果键盘会遮住一部分的控件可以设置如下:
android:windowSoftInputMode="adjustResize"