Android force pop-up to hide the input method.

Source: Internet
Author: User

When a Dialog is popped up, if the Dialog needs to input data, and then the input method needs to be closed after confirmation, there will always be various problems in the hide and show methods of the system, the most aggressive solution is to write a timer to pop up or close the input method on a regular basis.

Import java. util. timer; import java. util. timerTask; import android. content. context; import android. view. view; import android. view. inputmethod. inputMethodManager; import android. widget. editText; public class InputTools {// hide the virtual keyboard public static void HideKeyboard (View v) {InputMethodManager imm = (InputMethodManager) v. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); if (imm. isActive () {imm. hideSoftInputFromWindow (v. getApplicationWindowToken (), 0) ;}// display the virtual keyboard public static void ShowKeyboard (View v) {InputMethodManager imm = (InputMethodManager) v. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); imm. showSoftInput (v, InputMethodManager. SHOW_FORCED);} // force display or disable the public static void KeyBoard (final EditText txtSearchKey, final String status) {Timer timer = new Timer (); timer. schedule (new TimerTask () {@ Override public void run () {InputMethodManager m = (InputMethodManager) txtSearchKey. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); if (status. equals ("open") {m. showSoftInput (txtSearchKey, InputMethodManager. SHOW_FORCED);} else {m. hideSoftInputFromWindow (txtSearchKey. getWindowToken (), 0) ;}}, 300) ;}// use a timer to forcibly hide the virtual keyboard public static void TimerHideKeyboard (final View v) {Timer timer = new Timer (); timer. schedule (new TimerTask () {@ Override public void run () {InputMethodManager imm = (InputMethodManager) v. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); if (imm. isActive () {imm. hideSoftInputFromWindow (v. getApplicationWindowToken (), 0) ;}}, 10) ;}// whether the input method displays public static boolean KeyBoard (EditText edittext) {boolean bool = false; inputMethodManager imm = (InputMethodManager) edittext. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); if (imm. isActive () {bool = true;} return bool ;}}

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.