Android display and hide Input Keyboard usage, android Input Method

Source: Internet
Author: User

Android display and hide Input Keyboard usage, android Input Method

In some cases, you need to forcibly hide the Android Input Keyboard. If the current keyboard is displayed, You Need To forcibly hide the Input Keyboard when you click the slide panel. Common online methods include:

1. InputMethodManager imm = (InputMethodManager) getActivity ()
. GetSystemService (Context. INPUT_METHOD_SERVICE );
Imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS );

This is to reverse the input method status. If the current status is not displayed, it is displayed. If it is displayed, it is hidden. Therefore, it does not conform to the application scenarios described in this article.

2. imm. hideSoftInputFromInputMethod (passwdEdit. getWindowToken (), 0 );

The test on Android is invalid.

3. imm. hideSoftInputFromInputMethod (getActivity (). getCurrentFocus (). getWindowToken (), 0 );

Tested by myself, it still does not work. Uncle, I wasted two hours for this small feature.

4,Imm. hideSoftInputFromWindow (passwdEdit. getWindowToken (), 0 );

After testing, this is the only valid method!

In addition, some people say:

InputMethodManager imm = (InputMethodManager) this
. GetSystemService (Context. INPUT_METHOD_SERVICE );
Boolean isOpen = imm. isActive ();
Log. I (TAG, "imm. isActive () =" + isOpen );

The above code is used to determine whether the keyboard of the current input method is visible. It is totally nonsense and isOpen is always true. It is hereby recorded.

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.