Android Programmed EditText Popup Open and Close Tool Classes
- 2021-08-12 03:45:07
- OfStack
This article describes the EditText pop-up opening and closing tool class implemented by Android programming. Share it for your reference, as follows:
Requirements:
The use of code to achieve Android input box EditText to close the keyboard pop-up.
Code:
/**
* Open the keyboard
*
* @param editText Input box for operation
*/
public static void openKeyboard(EditText editText) {
// Set available focus
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
// Request for focus
editText.requestFocus();
// Call system input method
InputMethodManager inputManager = (InputMethodManager) editText
.getContext().getSystemService(INPUT_METHOD_SERVICE);
inputManager.showSoftInput(editText, 0);
}
/**
* Turn off the keyboard
*
* @param editText Input box for operation
*/
public static void closeKeyboard(EditText editText) {
// Turn off the keyboard
InputMethodManager imm = (InputMethodManager) editText
.getContext().getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
More readers interested in Android can check the topics of this site: "Android View View Skills Summary", "Android Layout layout Skills Summary", "Android Graphics and Image Processing Skills Summary", "Android Development Introduction and Advanced Tutorial", "Android Debugging Skills and Common Problem Solutions Summary", "Android Multimedia Operation Skills Summary (Audio, Video, Recording, etc.)", "Android Basic Component Usage Summary" and "Android Control Usage Summary"
I hope this article is helpful to everyone's Android programming.