讓鍵盤不佔空間和關閉軟鍵盤的方法
阿新 • • 發佈:2019-02-05
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"