Search code examples
androidandroid-softkeyboardbottomnavigationview

EditText cut in half by Soft Keyboard in ConstraintLayout


I'm trying to create a chat layout so I've got a recyclerview with an EditText (which use a rounded corner background) and a ImageButton to send the message, however when the soft keyboard shows up, it covers a little part of the EditText and the ImageButton.

I have android:windowSoftInputMode="adjustPan" in my AndroiManifest

I've tried:

  • using android:windowSoftInputMode="adjustResize it was taking everything up, my BottomNavigationView included (which I don't want)
  • putting app:paddingBottomSystemWindowInsets="@{true}" on my ConstraintLayout

Here is my layout:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_support"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:transcriptMode="alwaysScroll"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:layout_constraintBottom_toTopOf="@id/et_support"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:reverseLayout="true"
            tools:itemCount="3"
            tools:listitem="@layout/item_support_received" />

        <androidx.appcompat.widget.AppCompatEditText
            android:id="@+id/et_support"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@id/btn_support_send"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/rv_support"
            />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btn_support_send"
            android:layout_width="50dp"
            android:layout_height="50dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toEndOf="@id/et_support"
            app:layout_constraintTop_toBottomOf="@id/rv_support" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

and below my 2 images showing the issue:

enter image description here

enter image description here


Solution

  • I've found a workaround by doing this:

    1. I've gone back to adjustPan in my AndroidManifest
    2. In my fragment I've added:
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
    
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // Extension method I've created to hide/show the bottomNav
        requireActivity().showBottomNavBar(false)
    }
    
    override fun onDestroyView() {
        super.onDestroyView()
        requireActivity().showBottomNavBar(true)
    activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
    }