0

I want my soft keyboard to push content upward when it encounters it.

window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_INPUT_ADJUST_RESIZE)

This doesn't do anything, and if I use ADJUST_PAN, the ENTIRE screen moves with all the content. I just want the screen to be pushed up when content is encountered, and for the header not to move at all.

Here is my layout. It's a chat app, so i'm adding layouts programmatically.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/open_messsages_constraint"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".OpenMessages">

    <ScrollView
        android:id="@+id/messages_scroll2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


            <LinearLayout
                android:id="@+id/allMessage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                app:layout_constraintTop_toTopOf="parent"
                android:orientation="vertical">

            </LinearLayout>




    </ScrollView>


    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#ffffff"
        android:backgroundTint="#ffffff"
        app:layout_constraintBottom_toBottomOf="parent">

        <EditText
            android:id="@+id/messageInput"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:layout_marginLeft="20dp"
            android:layout_weight="4"
            android:background="@drawable/rounded_corner"
            android:backgroundTint="#f1f1f1"
            android:paddingLeft="20dp"
            android:textColorLink="#000000" />


        <com.google.android.material.button.MaterialButton
            android:id="@+id/sendMessageButton"
            android:layout_width="50dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:backgroundTint="#ffffff"
            android:gravity="center"
            android:stateListAnimator="@null"
            app:iconTint="#000000">

        </com.google.android.material.button.MaterialButton>
    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

How do I go about this?

Andrew Young
  • 684
  • 1
  • 13
  • 23
  • What's your layout looks like? – Md. Asaduzzaman Jan 07 '20 at 20:32
  • With ADJUST_RESIZE, you also need to have a layout that has a ScrollView plus the header you wont to move – Marcos Vasconcelos Jan 07 '20 at 20:45
  • @Md.Asaduzzaman Just edited with the layout! I add layouts programmatically inside of my code. It's a chat app. – Andrew Young Jan 07 '20 at 20:52
  • @MarcosVasconcelos Thank you. Could you elaborate a bit? I have a scroll view containing my layout. Code is added above. – Andrew Young Jan 07 '20 at 20:54
  • Put the Header View outisde of the ScrollView the content inside the scroll will get focused and the header will still be visible – Marcos Vasconcelos Jan 09 '20 at 01:41
  • I needed such an activity in a project and I had to implement it all by myself. All I did was to add `android:windowSoftInputMode="adjustResize"` and set `onGlobalLayoutListener` for my fragment and update UI manually. For more detail you could see this answer: https://stackoverflow.com/a/54288598/4158832 – ali73 Jan 28 '20 at 20:02

0 Answers0