Summary of solutions for maladjustment of Android soft keyboard

Summary of solutions for maladjustment of Android soft keyboard

preface:

Many developers who write the login interface will encounter a problem: when you click the input box in the login interface, the lower button will sometimes be blocked by the input box, which is not conducive to the user experience. Therefore, many people hope to squeeze the button when the soft keyboard pops up. Many developers want to monitor the state of the keyboard, which is undoubtedly a very troublesome practice.

We can set the property in the activity of androidmanifest.xml: Android: windowsoftinputmode = "adjustresize". When the soft keyboard pops up, we need to re layout the main window layout and call the onsizechanged method. Remember that when we set it to "adjustresize", our interface should not be set to full screen mode, Otherwise, setting this property will not have any effect. When we set Android: windowsoftinputmode = "adjustpan", the main window will not call the onsizechanged method, and part of the interface will be covered by the soft keyboard, so it will not be squeezed on the soft keyboard.

Let's test what the system does when the input method pops up after setting this attribute through a piece of code:

Override layout:

Our layout settings are:

Activity setting property of androidmanifest.xml: Android: windowsoftinputmode = "adjustresize"

Run the program, click the text box to view the debugging information:

From the debugging results, we can see that when we click the text box, the root layout calls onmeasure, onsizechanged and onlayout.

If the value of windowsoftinputmode is set to adjustpan, the main window of the activity does not resize the screen to make room for the soft keyboard. On the contrary, the content 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. This is usually not expected than resizing, because the user may turn off the soft keyboard to obtain interaction with the overwritten content.

In the above example, we change the property of androidmanifest.xml: Android: windowsoftinputmode = "adjustpan"

Rerun and click the text box to view the debugging information:

We can see that the system also performs the measurement and layout again, but we find that onsizechanged is not called during the layout process, which indicates that the size of the original layout is not changed before and after the input method pops up.

Of course, other properties can be set:

"stateUnspecified"

The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will select an appropriate state or theme dependent setting.

This is the default setting for software disk behavior.

"stateUnchanged"

The soft keyboard is maintained regardless of its last state, whether it is visible or hidden, when the main window appears in front.

"stateHidden"

When the user selects the activity, the soft keyboard is hidden -- that is, when the user determines to navigate to the activity, rather than return to it due to leaving another activity.

"stateAlwaysHidden"

The soft keyboard is always hidden when the main window of the activity gets the focus.

"stateVisible"

The soft keyboard is visible when that is normally appropriate (when the user navigates to the activity main window).

"stateAlwaysVisible"

When the user selects this activity, the soft keyboard is visible -- that is, when the user determines to navigate to the activity, rather than return to it due to leaving another activity.

"adjustUnspecified"

It is not specified whether the activity main window is resized to make room for the soft keyboard, or whether the content on the window gets the current focus on the screen is visible. The system will automatically select one of these modes, which mainly depends on whether any layout view of the contents of the window can scroll their contents. If there is such a view, the window will be resized. This assumption can make the contents of the scrolling window visible in a smaller area. This is the default behavior setting of the main window.

"adjustResize"

The main window of the activity is always resized to allow space for the soft keyboard

"adjustPan"

The activity main window does not resize the screen to allow space for a soft keyboard. On the contrary, the content 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. This is usually not expected than resizing, because the user may turn off the soft keyboard to obtain interaction with the overwritten content.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>