1

我见过类似的问题,但没有一个答案能解决我的问题。我有一个带有 editText 和按钮的简单 BottomSheetDialogFragment,当我选择 editText 时,键盘会覆盖按钮。

我测试了这个问题的几个答案,但没有任何运气: Bottom Sheet Fragment come up with keyboard

我的BottomSheetDialogFragment:

public class AddUserBottomSheetFragment extends BottomSheetDialogFragment {

    public static AddUserBottomSheetFragment newInstance() {
        return new AddUserBottomSheetFragment();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.bottom_sheet_add_user, container);
    }

}

片段对话框布局:

<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/bottomSheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/contacts_bottom_sheet_background"
    app:behavior_hideable="true"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
    app:behavior_peekHeight="500dp" >

    <EditText
        android:id="@+id/insert_user"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <Button
        android:id="@+id/add_user_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/contacts_add"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/insert_user" />

</androidx.constraintlayout.widget.ConstraintLayout>

我用这个方法在我的活动中显示它,并以一个简单的 linearLayout 作为参数:

public void showBottomSheet(View view) {
        AddUserBottomSheetFragment addDialogFragment = AddUserBottomSheetFragment.newInstance();
        addDialogFragment.show(getSupportFragmentManager(), "bottomSheetContainer");
    }
4

0 回答 0