Solution to the problem that the Android input panel is blocked by the keyboard

1. Introduction

In Android development, there are some very unoptimized experiences, such as the problem that the input panel will be covered by the soft keyboard. As shown below.
input panel
The picture above is the original picture covered by the soft keyboard.
Soft keyboard cover
The picture above is the effect of the soft keyboard.
Insert image description here
The picture above is the effect picture after the solution.

2. Solution

In actual use, something like the picture above will cause a very bad user experience. Therefore, we need solutions. On the Internet, this is basically achieved by modifying the activity attribute in AndroidManifest.xml. android:windowSoftInputMode="adjustPan" or android:windowSoftInputMode="adjustResize" attributes. But in my project, doesn't work. Just try another solution and finally solve the problem perfectly. To use it, use the fitsSystemWindows=true attribute on the transparent status bar.

3. Steps

1. First, add the android:fitsSystemWindows="true" attribute to the outermost layer of the page that needs to solve the covering problem.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true">

    <!--其他代码忽略-->
</RelativeLayout>

Now run the program and the problem will be solved. But there will be a problem, there will be a white bar at the top. This is obviously not the effect we want.

Guess you like

Origin blog.csdn.net/nanjumufeng/article/details/127753551