How to adjust layout when soft keyboard appears

https://w‮ww‬.lautturi.com
How to adjust layout when soft keyboard appears

To adjust the layout of your Android app when the soft keyboard appears, you can use the android:windowSoftInputMode attribute in the activity element of your app's AndroidManifest.xml file.

There are several different values that you can use for this attribute, depending on how you want the layout to be adjusted:

  • adjustPan: The layout is not resized, but paned to make room for the keyboard. This is the default behavior.
  • adjustResize: The layout is resized to make room for the keyboard. This can cause your layout to be resized and rearranged, potentially causing elements to move or be obscured.
  • stateUnspecified: The system will decide whether to pan or resize the layout based on the contents of the layout.
  • stateVisible: The keyboard is made visible, but the layout is not adjusted.
  • stateUnchanged: The keyboard is made visible and the layout is not adjusted, but the focus is not changed.
  • stateHidden: The keyboard is hidden.

Here's an example of how you might use the android:windowSoftInputMode attribute in your AndroidManifest.xml file:

<activity
    android:name=".MyActivity"
    android:windowSoftInputMode="adjustResize">
    <!-- other activity attributes -->
</activity>

This will cause the layout of the MyActivity activity to be resized when the soft keyboard appears.

Created Time:2017-11-01 12:04:58  Author:lautturi