Отключить отображение BottomSheetDialogFragment

У меня есть два макета фрагмента диалогового окна нижнего листа, которые я включил в CoordinatorLayout. CoordinatorLayout имеет RecyclerView, элементы которого показывают один фрагмент диалогового окна "Нижний лист" при нажатии. Первый фрагмент диалогового окна нижнего листа используется для обновления элементов представления ресайклера. Второй фрагмент диалогового окна нижнего листа используется для оплаты товаров. Проблема заключается в том, что когда я показываю второй нижний лист для оплаты и ошибочно нажимаю на элементы, первый нижний лист оказывается ниже второго. Есть ли способ отключить диалоговое окно первого нижнего листа или установить видимость, как в кнопках, когда отображается второй нижний лист

Вот мой XML


<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activities.CartActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/cart_tool_bar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay"/>

        </com.google.android.material.appbar.AppBarLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorWhiteShade">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/cart_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@color/colorWhiteDarker"
                android:padding="5dp"
                android:orientation="vertical">

                <androidx.cardview.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:cardCornerRadius="5dp"
                    android:layout_margin="2dp"
                    android:padding="5dp">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="5dp">

                        <TextView
                            android:id="@+id/tv_sub_total"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/sub_total"
                            android:textSize="20sp"
                            style="@style/TextAppearance.AppCompat.Large"/>

                        <TextView
                            android:id="@+id/sub_total"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/sub_total"
                            style="@style/TextAppearance.AppCompat.Body1"
                            android:textStyle="bold"
                            android:layout_alignParentEnd="true"
                            android:textSize="17sp"
                            />

                        <View
                            android:id="@+id/view"
                            android:layout_centerHorizontal="true"
                            android:layout_width="350dp"
                            android:layout_height="1dp"
                            android:background="@color/colorBlack20"
                            android:layout_margin="2dp"
                            android:layout_below="@id/sub_total"/>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/view"
                            android:layout_margin="2dp"
                            android:padding="2dp"
                            android:gravity="center"
                            android:orientation="horizontal">

                            <Button
                                android:id="@+id/btn_post_payment"
                                android:layout_width="wrap_content"
                                android:layout_height="35dp"
                                android:drawableStart="@drawable/pay_icon"
                                android:text="@string/pay"
                                android:background="@drawable/ripple"
                                android:layout_marginStart="2dp"
                                android:layout_marginEnd="2dp"
                                android:textColor="@android:color/white"
                                android:padding="5dp"
                                style="?attr/borderlessButtonStyle"
                                android:textAllCaps="false"/>

                        </LinearLayout>

                    </RelativeLayout>

                </androidx.cardview.widget.CardView>

            </LinearLayout>

        </RelativeLayout>

    </LinearLayout>

    <!-- Always include layout below all the other layouts -->
    <include layout="@layout/layout_cart_bottom_sheet"/>

    <!-- Always include layout below all the other layouts -->
    <include layout="@layout/layout_post_payment"/>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

Другая реализация, которая мне может понравиться, - это если 1-й диалог может проверить, отображается ли второй диалог, и предотвратить его повторное отображение.


person Emmanuel Njorodongo    schedule 09.06.2020    source источник


Ответы (1)


Вы можете установить видимость как:

<include layout="@layout/layout_cart_bottom_sheet" visibility="gone"/>

или установите идентификатор для макета как:

<include android:id="@+id/cart_bottomsheet" layout="@layout/layout_cart_bottom_sheet">

и переключать видимость с помощью findViewById и setVisibility.

person Sairaj Sawant    schedule 09.06.2020
comment
У вас есть способ программно отключить макет, вот что я пробовал, и приложение продолжает разрушаться: View layout_cart_bottom_sheet = findViewById (R.id.layout_cart_bottom_sheet); layout_cart_bottom_sheet.setVisibility (View.GONE); - person Emmanuel Njorodongo; 09.06.2020