Android Windowsoftinputmode Attribute Detailed _android

Source: Internet
Author: User

In the previous article, a simple introduction to how to implement the soft keyboard does not automatically eject, the use of the method is to set the Android:windowsoftinputmode property. So what does this attribute do, and what does he do? Today's article, is to explore the role of Android:windowsoftinputmode attributes.

First of all, from the name of this attribute, we can see how it works, this property is to set the window soft keyboard interactive mode.

The Android:windowsoftinputmode property has a total of 9 values, respectively:

Stateunspecified,stateunchanged,statehidden,statealwayshidden,statevisible,statealwaysvisible, Adjustunspecified,adjustresize,adjustpan.

When we set the properties, we can select one of these 9 values, or we can use "state...| The form of adjust "is set. So how do these values affect the interaction between a soft keyboard and a window? Below, we will test each of these 9 values, in the end is how to affect the soft keyboard display.

1.stateUnspecified

The state is not specified, when we do not set the Android:windowsoftinputmode property, the software by default is this interaction, the system will be based on the interface to take the corresponding soft keyboard display mode, for example, when the interface is only text and buttons, The soft keyboard will not automatically eject because there is no need for input. So, when the interface appears to get the focus of the input box, the soft keyboard will automatically pop-up it? This is not necessarily true! For example, in the following interface layout, the soft keyboard does not automatically eject.



That is, by default, in this case, the system is not sure whether the user needs a soft keyboard, and therefore does not automatically eject. But why is that not necessarily? This is because, if we are outside this layout, wrap up on the last

ScrollView, the soft keyboard will automatically bounce out!

Under this layout file, the soft keyboard will automatically eject

Copy Code code as follows:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >

<scrollview
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >

<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical" >

<button
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:onclick= "Toother"
android:text= "Jump"/>

<edittext
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>
</LinearLayout>
</ScrollView>

</LinearLayout>

This is indeed a very strange way of judging. Therefore, we can draw the conclusion that when the setting property is Stateunspecified, the system does not eject the soft keyboard by default, but when there is a scrolling demand for the interface of the input box with the focus, it automatically pops up the soft keyboard. As for why you have to emphasize the input box to get the focus, this is because, if not the input box to get focus, the soft keyboard is not automatically pop-up, so that the interface does not automatically eject the soft keyboard one of the solutions, is in the XML file, set a non-input box control to get the focus, thereby preventing the keyboard pop-up.

2.stateUnchanged

The meaning of Chinese is that the state does not change, how should we understand this sentence? In fact, it is very good to understand, that is, the current interface of the soft keyboard state, depending on the soft keyboard state of the previous interface. For example, if the current interface keyboard is hidden, then the interface after the jump, the soft keyboard is also hidden, if the current interface is displayed, then the interface after the jump, the soft keyboard is also displayed status.

3.stateHidden

As the name suggests, if we set this property, then the keyboard state must be hidden, regardless of the previous interface of what state, and regardless of the current interface has no input requirements, anyway, is not displayed. Therefore, we can set this property to control the soft keyboard does not automatically eject.

4.stateAlwaysHidden

This property can also let the soft keyboard hidden, but I do not know and Statehidden properties of the difference, originally wanted to go to StackOverflow to ask, but, great Wall, ah hehe ... May the disease soon prevail over the President

5.stateVisible

Set to this property, the soft keyboard can be summoned, even if there is no input box on the interface can be forced to call out.

6.stateAlwaysVisible

This property is also able to summon the keyboard, but it is slightly different from the statevisible attribute. For example, when we set the Statevisible property, if the current interface keyboard is displayed, and when we click the button to jump to the next interface, the soft keyboard will be hidden because the input box loses focus and when we return to the current interface, the keyboard is hidden at this time. But if we are set to statealwaysvisible, we jump to the next interface, the soft keyboard is still hidden, but when we come back again, the soft keyboard will be displayed. So, this always explains the difference, no matter what happens to the current interface (normal jump or the previous interface is returned by the user), the soft keyboard is the display state.

Speaking of which, I associate the above Statehidden and Statealwayshidden, and I estimate that the difference is the same, that is, Statealwayshidden is hidden anyway, but if you jump to the next interface, the soft keyboard is called out , then when the next interface is returned by the user, the keyboard should not be hidden, but I have not found the ability to jump to the next interface, but also let the current interface of the soft keyboard does not disappear, so for the time being can not verify.

7.adjustUnspecified

Starting from this attribute, it is not to set the display and hidden mode of the soft keyboard, but to set up the display relationship between the soft keyboard and the display content of the software. This option is also the default setting mode when you are not setting this value with us. In this case, the system chooses a different pattern depending on the interface. If the interface has controls that can be scrolled, such as Scrowview, the system reduces the size of the interface that can be scrolled, ensuring that all content is visible even if the soft keyboard is displayed. If there is no scrolling control in the layout, the soft keyboard may cover some content, and we can see the difference from the diagram below.

There is no scrolling control, the layout underneath the soft keyboard is blocked, if you want to modify, you can only hide the soft keyboard, and then select. Also, focus on the layout above, when we choose the input box down, the top of the title bar and layout is on the top of the soft keyboard. Remember this feature because there is a property that is not the same as the one behind it.


The layout has a sliding control, the system will automatically reduce the size of the entire interface, so we can soft keyboard above the small area to display all the input boxes.

This is the difference between the two display modes.

8.adjustResize

This property indicates that the main window of the activity is always resized to ensure that the soft keyboard displays space.

Let's look at the display effect first.

Note that the above title bar and button, set to the Adjustresize property, for the layout without sliding control, although still can not select all the input boxes, but the way the display of the window changed, the default properties, the entire layout is top up, But set to the Adjustresize property, the location of the layout has not changed, which is the biggest difference.


For layouts with sliding controls, the display effect is the same as the default.

9.adjustPan

If set to this property, the activity screen size does not adjust to ensure that the soft keyboard space, but to take another strategy, the system will be moved through the layout, to ensure that the user to enter the input box must be within the user's unemployment, so that users can see their input. For a layout without a scrolling control, this is actually the default setting, and if we choose a position below the top, the title bar and some controls will be topped up. But for the layout with the scrolling control, it's not quite the same, so let's look at the effect chart below.

First of all, this is the soft keyboard does not eject when there is a scrolling control display range, the bottom of the display is 9.


When we click on the 5 input box, we will find the following phenomenon.

The top can only be displayed to the button, the title bar is no longer seen.


And the bottom can only slide to 8, the following content is not able to slide.

Therefore, we can understand the effect of this attribute.

Through the above experiments, we can conclude that if we do not set the "Adjust" property, for the layout without scrolling control, the Adjustpan method is used, and for the layout of the scrolling control, the Adjustresize method is adopted.

Having learned the above knowledge, we can set different ways according to our own needs. Also, we have a clear understanding of how to make the interface load without displaying a soft keyboard.

    Good night, the program workers who are still struggling during the holidays.

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.