[BottomSheetDialogFragment] What's the recommended way to customize the behavior of a BottomSheetDialogFragment?
See original GitHub issueLet’s say I want my bottom sheet to skip its collapsed state. If I used a BottomSheetBehavior
I could just set skipCollapse
to true
. What’s the recommended way to achieve that on a BottomSheetDialogFragment
?
So far, I’ve been retrieving and modifying the BottomSheetDialogFragment
’s inner BottomSheetBehavior
myself, like so:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
dialog?.setOnShowListener { dialogInterface ->
val sheetDialog = dialogInterface as? BottomSheetDialog
val bottomSheet = sheetDialog?.findViewById<FrameLayout>(
com.google.android.material.R.id.design_bottom_sheet
)
bottomSheet?.let {
val behavior = BottomSheetBehavior.from(it)
behavior.skipCollapsed = true
// any other behavior modification here
}
}
}
However, this approach seems kind of hackish to me. Is there any alternative or is this the recommended way to achieve what I want?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:10 (1 by maintainers)
Top Results From Across the Web
android - Set state of BottomSheetDialogFragment to expanded
The Behavior is hidden in BottomSheetDialog, which is available to get the behavior If you would like not to change your parent layout...
Read more >BottomSheetDialogFragment Made Simpler | by Guneet Singh
If this is the first time you are using BottomSheet in your android app then this the best place to get started. The...
Read more >Full height bottom sheet dialog fragment on start ... - YouTube
if you need to make a bottom sheet dialog fragment take the whole screen height on start watch the video to see how.!This...
Read more >Android Bottom Sheet Behavior and Animated Button on Top ...
BottomSheetDialogFragment is a thin layer on top of the regular support library Fragment that renders your fragment as a modal bottom sheet.
Read more >BottomSheetDialogFragment - Android Developers
DialogFragment. ↳, androidx.appcompat.app.AppCompatDialogFragment. ↳, com.google.android.material.bottomsheet.BottomSheetDialogFragment ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve found a convenient way to config bottom sheet behavior using styles.
styles.xml
Go inside
Widget.MaterialComponents.BottomSheet.Modal
to see what settings you can modify.Theme.Design.BottomSheetDialog
and set that you want to override bottom sheet’s style with you own. Also can be placed instyles.xml
themes.xml
(hope you follow Google’s recommendations about packaging styles&themes)@renanferrari inside
onViewCreated
i used thati don’t know if it is the correct way