使用MaterialComponents主题后的BottomSheet样式

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

最近我转而使用com.google.android.material:material:1.0.0作为应用主题。

除了设置colorPrimarycolorPrimaryDarkcolorAccent以及使用MaterialButtonWidget.MaterialComponents.Button风格,活动/片段和bottomSheetFragment中的按钮颜色也不同!

在Activity / Fragment中没问题。但在BottomSheet中有不同的颜色(绿色)。

enter image description here

android material-design android-styles bottom-sheet material-components-android
1个回答
1
投票

我找到了解决这个问题的技巧:

为BottomSheetDialogFragment定义一个新样式:

 <style name="BaseBottomSheetDialog" parent="@style/Theme.MaterialComponents.Light.BottomSheetDialog">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
 </style>

并在BottomSheet类中使用它:

override fun getTheme(): Int = R.style.BaseBottomSheetDialog

最好使用基类并在其上实现getTheme()

© www.soinside.com 2019 - 2024. All rights reserved.