Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the default height of a BottomSheetDialog?

I've been using the new BottomSheetDialog added in Support Library 23.2, but I want to change the default height of the dialog. I know it probably has to do with the behavior_peekHeight attribute which controls the initial height, but how do I set that in the BottomSheetDialog when I don't have direct access to the BottomSheetBehavior?

like image 800
ianhanniballake Avatar asked Feb 25 '16 17:02

ianhanniballake


People also ask

What is peek height in bottom sheet?

You can just set param "maxHeight" to the root viewgroup of your bottom sheet. android:maxHeight=500dp.

What is behavior_peekHeight?

behavior_peekHeight attribute value used to represent how much pixels the bottom sheet will be visible. I set it to `0dp` because, later in the sample I wanted to demonstrate how to peek the sheet programmatically. BottomSheetBehavior allows the peek height being given programmatically.


1 Answers

You can set a bottomSheetDialogTheme in your Activity, overriding the bottomSheetStyle attribute's behavior_peekHeight:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">   <item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item> </style>  <style name="AppBottomSheetDialogTheme"        parent="Theme.Design.Light.BottomSheetDialog">   <item name="bottomSheetStyle">@style/AppModalStyle</item> </style>  <style name="AppModalStyle"        parent="Widget.Design.BottomSheet.Modal">   <item name="behavior_peekHeight">@dimen/custom_peek_height</item> </style> 

This same technique can be used for other attributes as well, such as adding <item name="behavior_hideable">true</item> to the AppModalStyle to change whether the bottom sheet is hideable.

like image 131
ianhanniballake Avatar answered Sep 21 '22 05:09

ianhanniballake