为什么BottomSheetDialog主题展开后不起作用?

问题描述 投票:0回答:1

当 BottomSheetDialog 处于展开状态时,我的主题资源无法工作?

@Override
protected void onStart() {
    super.onStart();
    behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}

调用“我的活动”时,主题资源不起作用?

val dialog = BottomSheetDialog(this,
    R.style.ThemeOverlay_MaterialComponents_RoundShapeBottomSheetDialog)

展开模式时,背景底片恢复默认,为什么会这样?

android bottom-sheet android-bottomsheetdialog
1个回答
0
投票

自定义BottomSheetDialog背景,您可以为BottomSheetDialog创建修改默认背景的自定义样式。

 <!-- styles.xml -->
<style name="CustomBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="android:background">@color/your_custom_background_color</item>
    <item name="bottomSheetDialogCornerRadius">0dp</item>
</style>

然后在创建 BottomSheetDialog 时应用此主题:

val dialog = BottomSheetDialog(this, R.style.CustomBottomSheetDialogTheme);
© www.soinside.com 2019 - 2024. All rights reserved.