How to move the button above the keyboard?

This question has been asked before, but I cannot find a good answer that works for me.

Here is my XML code (updated):

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Account Name"
        android:textSize="32dp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:id="@+id/textView" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:id="@+id/accountName"
        android:background="@drawable/edit_text_background"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:padding="10dp"
        android:backgroundTint="@color/abc_secondary_text_material_light" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Account Balance"
        android:textSize="32dp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:inputType="numberDecimal"
        android:id="@+id/accountBalance"
        android:background="@drawable/edit_text_background"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp"
        android:padding="10dp"
        android:backgroundTint="@color/abc_secondary_text_material_light"
        android:text="£"
        />


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_gravity="center_horizontal"
        android:layout_alignParentBottom="true"
        />

</RelativeLayout>

I tried using android:windowSoftInputMode="adjustPan|adjustResize", but it did not work.

I feel something is wrong with the layout of the XML ... It looks like this, and I want the button to move up when the keyboard appears:

enter image description here

+4
source share
3 answers

try using ScrollView at parent level

<ScrollView
            android:id="@+id/login_form"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
+2
source

in your AndroidManifest.xml

android:windowSoftInputMode="stateVisible|adjustResize"

in the style.xml file set the style of your activity as

<item name="android:windowActionBarOverlay">true</item>

make sure you are not using fullscreen .

0
source

.

.

android:windowSoftInputMode="stateHidden"

I want to save the layout inside scrollview, except for the view (the button in this case is ques) that you want to move using the keyboard.

0
source

All Articles