0

I have a common problem with the keyboard just a little overlapping EditText. I searched, but all the answers hadn't worked. I have android:windowSoftInputMode="adjustResize|stateAlwaysHidden"in AndroidManifest. Here's my layout:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>

        <import type="ru.express.app.domain.model.SendCheckBy" />

        <variable
            name="vm"
            type="ru.express.app.presentation.orders.dialogs.PayAllBottomSheetVM" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_pop_up_rounded_19"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        tools:context=".android.presentation.main.geo_location_dialog.GeoLocationDialogFragment"
        tools:ignore="SpUsage">

        <View
            android:layout_width="30dp"
            android:layout_height="3dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/bg_paging_indicator" />

        <TextView
            android:id="@+id/titleTextView"
            style="@style/Theme.ExpressRu.Text.Bold.21sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:gravity="center"
            android:lineSpacingExtra="10dp"
            android:text="@{vm.titleText}"
            tools:text="Оплатить все" />

        <TextView
            android:id="@+id/selectPaymentTitleTextView"
            style="@style/Theme.ExpressRu.Text.Bold.16sp"
            android:layout_marginTop="25dp"
            android:layout_marginHorizontal="13dp"
            android:layout_width="match_parent"
            android:gravity="start"
            android:text="@string/order_finished_select_payment_option" />

        <TextView
            android:id="@+id/cashPaymentTextView"
            style="@style/Theme.ExpressRu.Text.Regular.17sp"
            android:layout_width="match_parent"
            android:layout_marginHorizontal="13dp"
            android:layout_marginTop="20dp"
            android:text="@string/order_finished_cash"
            android:textColor="@drawable/bg_text_pressed"
            app:drawableEndCompat="@drawable/ic_round_red" />

        <TextView
            android:id="@+id/cardPaymentTextView"
            style="@style/Theme.ExpressRu.Text.Regular.17sp"
            android:layout_width="match_parent"
            android:layout_marginHorizontal="13dp"
            android:layout_marginTop="15dp"
            android:text="@string/order_finished_card"
            android:textColor="@drawable/bg_text_pressed"
            app:drawableEndCompat="@drawable/ic_round_gray" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="20dp"
            android:background="@color/gray_white_line" />

        <TextView
            android:id="@+id/chooseNumberOfChecksTitleTextView"
            style="@style/Theme.ExpressRu.Text.Bold.16sp"
            android:layout_marginTop="20dp"
            android:layout_marginHorizontal="13dp"
            android:layout_width="match_parent"
            android:gravity="start"
            android:text="@string/order_finished_select_number_of_checks" />

        <TextView
            android:id="@+id/oneCheckTextView"
            style="@style/Theme.ExpressRu.Text.Regular.17sp"
            android:layout_width="match_parent"
            android:layout_marginHorizontal="13dp"
            android:layout_marginTop="20dp"
            android:text="@string/order_finished_one_check"
            android:textColor="@drawable/bg_text_pressed"
            app:drawableEndCompat="@drawable/ic_round_red" />

        <TextView
            android:id="@+id/numberOfInvoicesTextView"
            style="@style/Theme.ExpressRu.Text.Regular.17sp"
            android:layout_width="match_parent"
            android:layout_marginHorizontal="13dp"
            android:layout_marginTop="15dp"
            android:text="@string/order_finished_by_number_of_invoices"
            android:textColor="@drawable/bg_text_pressed"
            app:drawableEndCompat="@drawable/ic_round_gray" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="20dp"
            android:background="@color/gray_white_line" />

        <TextView
            android:id="@+id/sendChecksTitleTextView"
            style="@style/Theme.ExpressRu.Text.Bold.16sp"
            android:layout_marginTop="20dp"
            android:layout_marginHorizontal="13dp"
            android:layout_width="match_parent"
            android:gravity="start"
            android:text="@string/order_finished_select_send_request" />

        <TextView
            android:id="@+id/phoneTextView"
            style="@style/Theme.ExpressRu.Text.Regular.17sp"
            android:layout_width="match_parent"
            android:layout_marginHorizontal="13dp"
            android:layout_marginTop="20dp"
            android:text="@string/order_finished_send_by_phone"
            android:textColor="@drawable/bg_text_pressed"
            app:drawableEndCompat="@drawable/ic_round_gray" />

        <EditText
            android:id="@+id/phoneEditText"
            style="@style/Theme.ExpressRu.TextInputEditText.Default"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_marginHorizontal="13dp"
            android:padding="10dp"
            android:inputType="phone"
            android:maxLength="12"
            android:onTextChanged="@{(text, start, before, count) -> vm.updateInput(text)}"
            android:text="@{vm.inputRequestText}"
            android:hint="@string/order_finished_send_by_phone_hint"
            android:backgroundTint="@color/white_blue_background"
            app:visible="@{vm.selectedSendBy == SendCheckBy.PHONE ? true : false}" />

        <TextView
            android:id="@+id/mailTextView"
            style="@style/Theme.ExpressRu.Text.Regular.17sp"
            android:layout_width="match_parent"
            android:layout_marginHorizontal="13dp"
            android:layout_marginTop="15dp"
            android:text="@string/order_finished_send_by_email"
            android:textColor="@drawable/bg_text_pressed"
            app:drawableEndCompat="@drawable/ic_round_gray" />

        <EditText
            android:id="@+id/mailEditText"
            style="@style/Theme.ExpressRu.TextInputEditText.Default"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_marginHorizontal="13dp"
            android:padding="10dp"
            android:inputType="textEmailAddress"
            android:onTextChanged="@{(text, start, before, count) -> vm.updateInput(text)}"
            android:text="@{vm.inputRequestText}"
            android:hint="@string/order_finished_send_by_email_hint"
            android:backgroundTint="@color/white_blue_background"
            app:visible="@{vm.selectedSendBy == SendCheckBy.EMAIL ? true : false}" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="25dp"
            android:background="@color/gray_white_line" />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/confirmButton"
            style="@style/Theme.ExpressRu.Button.Permission"
            android:layout_width="match_parent"
            android:layout_marginStart="13dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="13dp"
            android:backgroundTint="@color/red_main"
            android:text="@string/confirm"
            android:textColor="@color/white" />

        <Space
            android:id="@+id/space"
            android:layout_width="wrap_content"
            android:layout_height="23dp" />

    </LinearLayout>
</layout>

I tested recommendations from: Keyboard hides BottomSheetDialogFragment Bottom Sheet Fragment comes up with keyboard

EJ Travel
  • 15
  • 5

1 Answers1

0

This one solved my problem. I've put it into OnViewCreated method in the BottomSheetDialogFragment.

    binding.root.addGlobalLayoutListener(true) {
        val keyboardHeight =
            dialog?.window?.decorView?.rootWindowInsets?.getInsets(
                WindowInsetsCompat.Type.ime()
            )?.bottom
        binding.root.setPadding(0, 0, 0, keyboardHeight ?: 0)
    }
EJ Travel
  • 15
  • 5