如何更改BottomSheetDialog的默认高度? [英] How do I change the default height of a BottomSheetDialog?

查看:1166
本文介绍了如何更改BottomSheetDialog的默认高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用支持库23.2 中添加的新BottomSheetDialog a>,但是我想更改对话框的默认高度。我知道它可能与控制初始高度的 behavior_peekHeight 属性有关,但是如何在 BottomSheetDialog 当我无法直接访问 BottomSheetBehavior

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆