Android Side Sheet Dialog Dismiss on Content View Click

1 week ago 5
ARTICLE AD BOX

Side Sheet Dialog Layout:

<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:layout_width="match_parent" android:layout_height="match_parent"> </androidx.constraintlayout.widget.ConstraintLayout>

Code (in Fragment):

fun showSideSheetDialog() { val sideSheetView = layoutInflater.inflate(R.layout.side_sheet_first, null) val sideSheetDialog = SideSheetDialog(requireContext()).apply { setContentView(sideSheetView) setSheetEdge(Gravity.END) } sideSheetDialog.show() }

Result: click on content View will dismiss (cancel) the Side Sheet Dialog

enter image description here

Workaround: use setCanceledOnTouchOutside(false), but it will lose the ability to close this dialog by clicking the outside area.

PS: My base theme is Theme.Material3.DayNight.NoActionBar.

Read Entire Article