Клавиатура скрывает BottomSheetDialog

Я использовал BottomSheetDialog для получения некоторого ввода от клиента, мое представление содержит TextInputLayout и кнопку под TextInputLayout, когда пользователь нажимает на TextInputLayout, кнопка ниже скрывается клавиатурой, поэтому мне нужна эта кнопка над клавиатурой, пробовал много возможностей, но не в состоянии это исправить. Прикрепляю фотографии по этому поводу.

введите здесь описание изображения введите здесь описание изображения

Код Java-файла (активности):

BottomSheetDialog customTipAmountBottomSheetDialog;
private void showCustomTipAmountBottomSheet() {
    customTipAmountBottomSheetDialog = new BottomSheetDialog(OrderActivity.this);
    View customTipAmountBottomSheetView = getLayoutInflater().inflate(R.layout.custom_tip_amount_bottom_sheet, null);
    customTipAmountBottomSheetDialog.setContentView(customTipAmountBottomSheetView);

    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
    assert imm != null;
    imm.showSoftInput(binding.invoiceDialog.submit, InputMethodManager.RESULT_HIDDEN);

    TextInputLayout customTipAmountBSTIL = customTipAmountBottomSheetView.findViewById(R.id.customTipAmountBSTIL);
    EditText customTipAmountBSET = customTipAmountBottomSheetView.findViewById(R.id.customTipAmountBSET);
    ImageView submit_custom_tip_amount = customTipAmountBottomSheetView.findViewById(R.id.submit_custom_tip_amount);

    submit_custom_tip_amount.setOnClickListener(view -> {
        String amount = customTipAmountBSET.getText().toString();
        if (amount.length() > 0 && Integer.parseInt(amount) > 0) {
            int tipAmount = Integer.parseInt(amount);
            if (tipAmount > 0 && tipAmount < 51) {
                binding.invoiceDialog.customTipAmountTv.setText(tipAmount);
                captainTipAmount = tipAmount;
                customTipAmountBottomSheetDialog.dismiss();
            } else {
                customTipAmountBSTIL.setError("Amount should be less than 50");
            }
        } else {
            customTipAmountBSTIL.setError("Requires a valid amount");
        }
    });

    customTipAmountBottomSheetDialog.show();
}

файл макета custom_tip_amount_bottom_sheet.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_height="match_parent">
<TextView
    android:id="@+id/customTipAmountCaptainNameTv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    android:text="Tip amount for Rapido Captain"
    android:textColor="@color/black"
    android:textSize="16sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<android.support.design.widget.TextInputLayout
    android:id="@+id/customTipAmountBSTIL"
    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="8dp"
    android:hint="Enter amount"
    app:boxBackgroundColor="@color/grey_100"
    app:boxCornerRadiusTopEnd="8dp"
    app:boxCornerRadiusTopStart="8dp"
    app:errorEnabled="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/customTipAmountCaptainNameTv">

    <EditText
        android:id="@+id/customTipAmountBSET"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:digits="1234567890"
        android:ems="2"
        android:focusable="true"
        android:imeOptions="actionDone"
        android:inputType="phone" />
</android.support.design.widget.TextInputLayout>


<ImageView
    android:id="@+id/submit_custom_tip_amount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="submitFeedbackConfirmationPopUp"
    android:padding="@dimen/margin_8"
    app:layout_constraintBottom_toBottomOf="@+id/customTipAmountBSTIL"
    app:layout_constraintEnd_toEndOf="@+id/customTipAmountBSTIL"
    app:layout_constraintTop_toTopOf="@+id/customTipAmountBSTIL"
    app:srcCompat="@drawable/ic_arrow_forward_black_24dp" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    android:text="Button"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/submit_custom_tip_amount" />

in Manifest file for activity file:

android:windowSoftInputMode="adjustPan"

Пробовал много искать, но так и не смог это исправить. я получил один ответ, связанный с моей проблемой, но он был с BottomSheetFragment()клавиатура скрывает BottomSheetFragment, но мне нужно с диалоговым окном нижнего листа. Пожалуйста, помогите мне в этом.

Дайте мне знать, что требуется дополнительная информация.


person Ram Koti    schedule 26.09.2018    source источник


Ответы (2)


В методе onCreate() в вашем классе java активности используйте метод ниже.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Несколько дней назад я столкнулся с той же проблемой. Затем, используя эту часть кода в моем методе onCreate(), проблема была решена.

Образец:

Нижний лист с настраиваемой программной клавиатурой

person Zakaria Hossain    schedule 15.10.2018
comment
Это может работать в действии, но не работает с BottomSheetDialog. я проверил себя - person Kwnstantinos Nikoloutsos; 26.04.2019
comment
Вы можете использовать это внутри onCreateView во фрагменте. getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - person Zakaria Hossain; 26.04.2019

Есть способы добиться этого:

1. Напишите приведенный ниже код в файл манифеста Android под тегом <activity>:

android:windowSoftInputMode="stateHidden|adjustResize"

2. Напишите приведенный ниже код в свой onCreate() метод действия:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Я надеюсь, что это работает для вас.

person Android Geek    schedule 20.03.2019