Element fixed on top of the keyboard

Asked

Viewed 305 times

1

I created a RelativeLayout property match_parent height so you can fill the entire screen. Inside it I insert a LinearLayout property alignParentBottom having value true to secure the element to the footer.

When I click and focus on EditText, my keyboard superimposes the element. I would like that LinearLayout remained fixed on top of device keyboard.

To be clear I took this image from the Twitter app:

inserir a descrição da imagem aqui

Code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="O que esta acontecendo?"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="#666"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">
        
    </LinearLayout>
</RelativeLayout>

Just below is a GIF showing the top code working. When is given the focus on EditText, the gray part is superimposed by the keyboard. I’ve tried using android:windowSoftInputMode="adjustPan|adjustResize" in my Activity, but it didn’t work.

inserir a descrição da imagem aqui

How do I make my element remain fixed on top of the keyboard without being overlaid?

1 answer

1

Have you tried adding adjustPan to your manifest?

Example:

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

This will make that when the keyboard is opened, it pushes the entire layout to stand on top of the keyboard.

  • Leonardo, it doesn’t work that way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.