Android soft keyboard display mode and opening and closing modes (recommended)

Android soft keyboard display mode:

Android defines a property named windowsoftinputmode, which allows programs to control the adjustment of the active main window. We can set the activity in androidmanifest.xml. For example: Android: windowsoftinputmode = "stateunchanged|adjustpan"

There are two optional values for this attribute, one is the state control of the soft keyboard, and the other is the adjustment of the active main window. The previous part of this article will not be discussed. Please refer to the Android documentation yourself.

Mode 1, compression mode

If the value of windowsoftinputmode is set to adjustresize, the main window of the activity is always resized to make room for the soft keyboard.

We use a piece of code to test what the system does when the input method pops up after we set this attribute.

Mode 2, translation mode

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"

Mode 3 automatic mode

When the property windowsoftinputmode is set to adjustuspecified, it is not specified whether the main window of the activity is resized to make room for the soft keyboard, or whether the content on the window is visible with the current focus on the screen. 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.

In other words, the system automatically determines whether to use translation mode or compression mode. The decisive factor is whether the content can be scrolled.

Android soft keyboard on and off mode:

Toggle soft keyboard:

Turn off the soft keyboard

The above is the Android soft keyboard display mode and opening and closing mode (recommended) introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>