Android hidden IME hidden soft keyboard Full solution

Source: Internet
Author: User

Some projects need to hide the input method, such as the login page, after the successful login to hide the input method, such as posting a post, or the message is
After the successful release, you need to hide the input method, such as a page of both EditText and spinner and other controls, when you enter the end to click
The spinner control is a soft keyboard that is not hidden, which is affecting the user experience.
Here I wrote a static method, the need can be placed in the Util package, need to use when the direct call on OK
/**
* Hide IME Panel
*
* @param activity
*/
public static void Hideinputmethod (activity activity) {
if (null = = activity) {
Return
}

if (null! = Activity.getcurrentfocus () && null! = Activity.getcurrentfocus (). Getwindowtoken ())

{

Inputmethodmanager IMM = (inputmethodmanager) activity.getsystemservice (Activity.input_method_service);

Imm.hidesoftinputfromwindow (Activity.getcurrentfocus (). Getwindowtoken (), INP Utmethodmanager.hide_not_always);
}
}


The parameter is activity, and when invoked in an activity, it is just a direct move through the activity.

For example, Util.hideinputmethod (mainactiviity.class); util is a generic class name.

In some cases also need to hide the input method, such as post a message, jump to another interface, in the second interface actually can also see the loss of

The user experience is too bad.


so the question is, how to solve the problem, the answer to see below
In the Androidmainfirst.xml file, add the activity that you registered

Android:windowsoftinputmode= "Statealwayshidden|adjustnothing"


Windowsoftinputmode This is used to control the software disk, the following is a few worthy of meaning, you can refer to a look.
Meaning of each value:
"1" stateunspecified: The state of the soft keyboard is not specified, the system will select an appropriate state or a theme-dependent setting
"2" stateunchanged: When this activity appears, the soft keyboard will remain in the previous activity, whether it is hidden or displayed
"3" Statehidden: When the user chooses activity, the soft keyboard is always hidden
"4" Statealwayshidden: When the Activity main window gets the focus, the soft keyboard is always hidden
"5" statevisible: Soft keyboard is usually visible
"6" statealwaysvisible: When the user chooses activity, the soft keyboard always displays the state
"7" adjustunspecified: Default setting, usually determined by the system to hide or show
"8" adjustresize: The activity always adjusts the screen size to allow space for the soft keyboard
"9" Adjustpan: The contents of the current window will automatically move so that the current focus is never covered by the keyboard and the user can always see the part of the input content

Android hidden IME hidden soft keyboard Full solution

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.