让键盘不占空间和关闭软键盘的方法

来源:互联网 发布:中国科技实力 知乎 编辑:程序博客网 时间:2024/04/28 18:51
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"

0 0
原创粉丝点击