Display and hide of Keyboard, and display and hide of Keyboard

Source: Internet
Author: User

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 ();
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.