禁止显示 BottomSheetDialogFragment
Disable BottomSheetDialogFragment from showing
我有两个底部 Sheet 对话框片段布局,我已将其包含在 CoordinatorLayout
中。 CoordinatorLayout
有一个 RecyclerView
,其项目在被单击时显示一个底部 Sheet 对话框片段。第一个底部 sheet 对话框片段用于更新回收站视图的项目。第二个 Bottom Sheet 对话框片段用于执行项目付款。我遇到的问题是,当我显示第二个底部 Sheet 进行付款并错误地点击第一个底部 sheet 的项目时,它位于第二个底部下方。有没有一种方法可以将第一个底部 sheet 对话框设置为禁用,或者在显示第二个底部 sheet 时将可见性设置为像按钮一样消失
这是我的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>
我可能喜欢的另一个实现是第一个对话框是否可以检查第二个对话框是否已经显示并阻止它再次显示
您可以将可见性设置为:
<include layout="@layout/layout_cart_bottom_sheet" visibility="gone"/>
或将布局的 ID 设置为:
<include android:id="@+id/cart_bottomsheet" layout="@layout/layout_cart_bottom_sheet">
并使用 findViewById
和 setVisibility
切换可见性。
我有两个底部 Sheet 对话框片段布局,我已将其包含在 CoordinatorLayout
中。 CoordinatorLayout
有一个 RecyclerView
,其项目在被单击时显示一个底部 Sheet 对话框片段。第一个底部 sheet 对话框片段用于更新回收站视图的项目。第二个 Bottom Sheet 对话框片段用于执行项目付款。我遇到的问题是,当我显示第二个底部 Sheet 进行付款并错误地点击第一个底部 sheet 的项目时,它位于第二个底部下方。有没有一种方法可以将第一个底部 sheet 对话框设置为禁用,或者在显示第二个底部 sheet 时将可见性设置为像按钮一样消失
这是我的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>
我可能喜欢的另一个实现是第一个对话框是否可以检查第二个对话框是否已经显示并阻止它再次显示
您可以将可见性设置为:
<include layout="@layout/layout_cart_bottom_sheet" visibility="gone"/>
或将布局的 ID 设置为:
<include android:id="@+id/cart_bottomsheet" layout="@layout/layout_cart_bottom_sheet">
并使用 findViewById
和 setVisibility
切换可见性。