![](/img/trans.png)
[英]Android BottomSheetDialog with EditText covered by keyboard
[英]Keyboard covers an EditText in a BottomSheetDialog
我有一個鍵盤的常見問題,只是有點重疊 EditText。 我搜索了,但所有的答案都沒有奏效。 我在 AndroidManifest 中有android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
。 這是我的布局:
<?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>
我測試了以下建議: Keyboard hides BottomSheetDialogFragment Bottom Sheet Fragment come up with keyboard
這個解決了我的問題。 我已將其放入 BottomSheetDialogFragment 的 OnViewCreated 方法中。
binding.root.addGlobalLayoutListener(true) {
val keyboardHeight =
dialog?.window?.decorView?.rootWindowInsets?.getInsets(
WindowInsetsCompat.Type.ime()
)?.bottom
binding.root.setPadding(0, 0, 0, keyboardHeight ?: 0)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.