Display and hide of Keyboard, and display and hide of Keyboard
A tool class for controlling keyboard display and hiding
Public class KeyBoardTool {
/**
* If the input method is displayed in the window, it is hidden. Otherwise, it is displayed.
* @ Param context
*/
Public static void showOrhide (Context context ){
InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS );
}
/**
* Display the soft keyboard View
* @ Param context
* @ Param view: view for receiving input from the soft keyboard
*/
Public static void showKeyBoard (Context context, View view ){
InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. showSoftInput (view, InputMethodManager. SHOW_FORCED );
}
/**
* Hide the keypad
* @ Param context
* @ Param view: view for receiving input from the soft keyboard
*/
Public static void hideKeyBoard (Context context, View view ){
InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. hideSoftInputFromWindow (view. getWindowToken (), InputMethodManager. HIDE_NOT_ALWAYS );
}
/**
* Obtain the status of the input method enabled.
* @ Param context
* @ Return if true is returned, the input method is enabled.
*/
Public static boolean getStateOfKeyBoard (Context context ){
InputMethodManager imm = (InputMethodManager) context. getSystemService (Context. INPUT_METHOD_SERVICE );
Return imm. isActive ();
}
}