Display Mode and enable and disable mode of the Android keypad

Source: Internet
Author: User
Tags xml attribute

Android keypad display mode:

Android defines an attribute named windowSoftInputMode, which allows the program to control the adjustment method of the main activity window. We can set the Activity in AndroidManifet. xml. For example, android: windowSoftInputMode = "stateUnchanged | adjustPan"

This attribute has two optional values: the Status Control of the soft keyboard and the adjustment of the main activity window. The previous sections will not be discussed in this article. Please refer to the android documentation on your own.
Mode 1: compression mode
If the value of windowSoftInputMode is set to adjustResize, the main window of the Activity is always adjusted to reserve space for the keyboard.

Let's use a piece of code to test what the system did when we set this attribute and the input method popped up.

Mode 2: translation mode
If the value of windowSoftInputMode is set to adjustPan, the screen size of the Activity main window is not adjusted to reserve space for the soft keyboard. On the contrary, the content of the current window is automatically moved so that the current focus is not overwritten by the keyboard and the user can always see the part of the input content. This is usually not expected to be adjusted because the user may close the keyboard to obtain interaction with the covered content.
In the above example, we will change the AndroidManifest. xml Attribute: android: windowSoftInputMode = "adjustPan"

Mode 3 automatic mode
When the windowSoftInputMode attribute is set to adjustUspecified, it is not specified whether to adjust the size of the Activity main window to leave space for the soft keyboard, or whether the content in the window is visible to the current focus on the screen. The system automatically selects one of these modes, depending on whether the content of the window has any layout view that can scroll their content. If there is such a view, the window will be adjusted. This assumption can make the content of the scrolling window visible in a small area. This is the default behavior settings for the main window.

That is to say, the system automatically determines whether to adopt the translation mode or the compression mode, and determines whether the content can be rolled.

How to enable and disable the Android keypad:

Switch the keyboard:

InputMethodManager imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE); // obtain the InputMethodManager instance if (imm. isActive () {// If you enable imm. toggleSoftInput (InputMethodManager. SHOW_IMPLICIT, InputMethodManager. HIDE_NOT_ALWAYS); // close the keyboard. The method for enabling the keyboard is the same. This method switches the Enable and disable statuses}

Close the keypad

if(getCurrentFocus()!=null){((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS); }


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.