Android hide Input Method hide soft keyboard full solution

Source: Internet
Author: User

Android hide Input Method hide soft keyboard full solution
Some projects need to hide the input method, such as the login page. After Successful Logon, you need to hide the input method, or publish a post or the message is
After the release is successful, you need to hide the input method. For example, if there are EditText and Spinner controls on a page, click
The Spinner control is not hidden from the keyboard, which affects the user experience.
Here I have written a static method. If you need it, you can store it in the Util package. If you need it, you can call it directly.
/**
* Hide the input method 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 (), InputMethodManager. HIDE_NOT_ALWAYS );
}
}


The parameter is Activity. When an Activity is called, you can simply put it in,

For example, Util. hideInputMethod (MainActiviity. class); util is a common class name.

In some cases, you also need to hide the input method. For example, after publishing a write information, you can see the input in the second interface when you jump to another interface.

The user experience is too bad.


Now, how can we solve this problem? The answer is as follows:
In the AndroidMainfirst. xml file, add

Android: windowSoftInputMode = "stateAlwaysHidden | adjustNothing"


WindowSoftInputMode is used to control the software disk. The following are some meanings. For more information, see.
Meanings of values:
[1] stateUnspecified: the soft keyboard status is not specified. The system selects an appropriate status or depends on the topic settings.
[2] stateUnchanged: When this activity appears, the soft keyboard will remain in the status of the previous activity, whether hidden or displayed
[3] stateHidden: When you select activity, the keyboard is always hidden.
[4] stateAlwaysHidden: when the Activity Main Window gets the focus, the keyboard is always hidden.
[5] stateVisible: the soft keyboard is usually visible.
[6] stateAlwaysVisible: when the activity is selected, the soft keyboard always displays the status
[7] adjustUnspecified: the default setting. It is usually determined by the system whether to hide or display it.
[8] adjustResize: The Activity always adjusts the screen size to leave space for the soft keyboard.
[9] adjustPan: the content of the current window will be automatically moved so that the current focus is not overwritten by the keyboard and the user can always see the content of the input.

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.