There is a way with which you can do this:
In XML layout of the dialog:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/sliderLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="true"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
// Place your layout code here and your code should be in one tag that can be any Layout.
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
In the view, where you are calling the dialog, make a BottomSheetBehavior
variable of the RelativeLayout
type.
private lateinit var bottomSheetBehaviour: BottomSheetBehavior<RelativeLayout>
Then, call your dialog like this,
val dialog = BottomSheetDialog(this)
val dialogBinding = binding of your dialog layout
dialog.setContentView(dialogBinding.root)
bottomSheetBehaviour = BottomSheetBehavior.from(dialogBinding.sliderLayout)
dialog.show()
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED
bottomSheetBehaviour.peekHeight = dialogBinding.sliderLayout.height
This will make your dialog layout go full screen when the user slides up the layout.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…