我一直在使用Support Library 23.2中添加的新BottomSheetDialog,但是我想更改对话框的默认高度。我知道这可能与控制初始高度的behavior_peekHeight
属性有关,但是当我无法直接访问BottomSheetDialog
时如何在BottomSheetBehavior
中进行设置?
最佳答案
您可以在Activity中设置一个bottomSheetDialogTheme
,以覆盖bottomSheetStyle
属性的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
来更改底部工作表是否可隐藏。