The solution to put the layout on top when Android pops up the soft keyboard

When the Android soft keyboard pops up, the layout will be pushed up, you can try the following solutions:

  1. Use android:windowSoftInputModeattribute : Set android:windowSoftInputModethe 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>

    adjustResizeoption to automatically adjust the layout to fit the height of the soft keyboard.

  2. Using android:fitsSystemWindowsthe attribute : Adding android: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>

  3. Use android:isScrollContainerattribute : Add android: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.

Guess you like

Origin blog.csdn.net/xige1995/article/details/130132392