<activty android:windowSoftInputMode="stateHidden">
</activity><activty android:windowSoftInputMode="adjustResize">
</activity>InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);EditText mEditText = (EditText) mView.findViewById(R.id.some_edit_text);
mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// When loss focus, manually hide the soft keyboard
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
});mEditText.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);or
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);- When keyboard appear (or switches),
heightDiffwill change to 0, then change to height of Keyboard (300~500px) - When keyboard disappear,
heightDiffwill change to 0, then change to height of vitual buttons (50px for Nexus 7, 75px for Nexus 5)
getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = mRootView.getRootView().getHeight() - mRootView.getHeight();
if (heightDiff > 100) {
onKeyboardDidAppear();
} else if (heightDiff > 0) {
onKeyboardDidDisappear();
}
}
});