Solution to the problem of overwriting the input box when the Android input method pops up

When an activity contains an input box, we click the input box to pop up the input method interface. The change effect of the whole interface is related to the Android: windowsoftinputmode attribute set in the manifest. Generally, the values that can be set are as follows,

For specific settings, you can view the official documents. Today, we mainly solve the problem that the input box will be overwritten when the input method pops up.

What will be covered?

In the Android application, if an activity sets the full screen attribute theme.light.notitlebar.fullscreen or the Android: windowtranslucentstatus attribute in the topic corresponding to the activity, the setting method is: < item name = "Android: windowtranslucentstatus" > true < / item >, which is if the corresponding page contains an input box, It will cause the soft keyboard to pop up when clicking the input box, and the keyboard will cover the input box, resulting in the input box being invisible.

Why?

This is actually because the adjustresize attribute has failed when the screen is full. The problem is a bug in the system. Refer to the link. Adjustresize doesn't work. Is there any other way to solve it? At this time, we can set the adjust attribute to the adjustpan attribute, which will not become invalid. However, since the adjustpan will shift the whole page to leave space for the input method, there will be a jitter effect and the experience is very poor. Is there a better way to experience the effect?

Solution:

If FrameLayout is adopted for the layout, you can duplicate a custom FrameLayout and set the Android: fitssystemwindows property of FrameLayout to true. The XML settings are as follows

We customize the FrameLayout as insetframelayout, and the insetframelayout code is as follows:

Official solution:

In fact, the official also found the problem, so FrameLayout was rewritten under android.support.design.internal to solve the problem, but this class was marked hide.

Using any of the above methods can solve the problem of overwriting the input box after the input method pops up.

Other questions?

In the process of using, we found user feedback that as long as we enter the page with this layout, it will crash. We checked the crash log and found that some mobile phones use the same Android system, and the version is 19, Android 4.4. X, a rewritten system, and the code loading method of the system has been rewritten.

Why did it collapse?

Our code uses windowinsets. This class is only provided by API 20. Therefore, there is no such code in the system of 19, but the system parses this class when XML is inflated, resulting in classnotfound.

New solutions!

The new solution still adopts the above method, but different layouts will be written for different versions. Different layouts will be provided for API above 20 and below 20 respectively, which is realized by using the system qualifier. After that, the above method will be adopted for API above 20, and onapplywindoinsets will be copied after 20. In this way, it is OK for different versions to load different codes.

To sum up, the whole solution has been completed. If there is an updated solution, please share it.

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