When the Android soft keyboard pops up, the layout will be pushed up, you can try the following solutions:
-
Use
android:windowSoftInputMode
attribute : Setandroid:windowSoftInputMode
the attribute of Activity in the AndroidManifest.xml file to automatically adjust the layout when the soft keyboard pops up. For example:xmlCopy code
<activity android:name=".MainActivity" android:windowSoftInputMode="adjustResize"> </activity>
adjustResize
option to automatically adjust the layout to fit the height of the soft keyboard. -
Using
android:fitsSystemWindows
the attribute : Addingandroid:fitsSystemWindows="true"
the attribute to the root view of the layout tells the Android system that the layout has adapted to the system window and does not need to be adjusted. For example:xmlCopy code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:orientation="vertical"> <!-- 在这里添加布局 --> </LinearLayout>
-
Use
android:isScrollContainer
attribute : Addandroid:isScrollContainer="true"
attribute to the layout to make the layout a scrollable container, so as to avoid the problem that the layout is blocked by the soft keyboard. For example:xmlCopy code
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:isScrollContainer="true"> <!-- 在这里添加布局 --> </ScrollView>
No matter which method is used, the layout needs to be reasonably designed to ensure that the layout can fit the screen when the soft keyboard pops up and will not be blocked or overlapped.