如何更改BottomSheetDialog的默认高度? [英] 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
?
推荐答案
您可以在活动中设置 bottomSheetDialogTheme
,覆盖 bottomSheetStyle
属性的 behavior_peekHeight
:
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>
此技术也可以用于其他属性,例如添加 < item name = behavior_hideable> true< / item>
到 AppModalStyle
来更改底部工作表是否可隐藏。
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.
这篇关于如何更改BottomSheetDialog的默认高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!