》键盘的隐藏XML配置: adjustPan;stateHidden
android:windowSoftInputMode="stateHidden"
》键盘显示隐藏的Java代码实现
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
/**
*
* @author 作者 :desaco
*
* @version 创建时间:2016-1-4 上午10:17:11
*
*/
public class InputSoftKeyboardUtils {
private InputSoftKeyboardUtils() {
}
/**
* hide keyboard
*/
public static void hideKeyboard(View view,Context context) {
InputMethodManager inputMethodManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen = inputMethodManager.isActive();
if(isOpen){
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘
}
}
/**
* show keyboard
*/
public static void showKeyboard(Context context) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT);
}
}