Search code examples
androidkeyboardandroid-softkeyboardsoft-keyboard

How to move the layout above of soft keyboard when it is shown


I have a simple layout for my activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/editTextName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/buttonCancel"
        android:layout_alignParentTop="true" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="cancel" />


</RelativeLayout>

and when I touch on EditText soft keyboard appears but my button hides beyond the keyboard !

but I wanna the Button move up (above of) the keyboard.

I added this line of code to AndroidManifest but nothing changed.

<activity
    android:name=".Activity"
    android:windowSoftInputMode="adjustPan|adjustResize">
</activity>

Solution

  • According to the official documentation adjustPan and adjustResize have an opposite behaviour and therefore I don't think they should be used together. Try just android:windowSoftInputMode="adjustResize" , worked for me.