使用 MaterialComponents 主题后的 BottomSheet 样式
BottomSheet style after using MaterialComponents Theme
最近我改用 com.google.android.material:material:1.0.0
作为应用主题。
除了设置colorPrimary
、colorPrimaryDark
和colorAccent
并使用MaterialButton
和Widget.MaterialComponents.Button
样式外,activity/fragment和bottomSheetFragment中的按钮颜色不一样!
在 Activity/Fragment 中可以。但在 BottomSheet 中有不同的颜色(绿色)。
为 BottomSheetDialogFragment 定义新样式:
<style name="MyBottomSheetStyle" 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>
您可以通过应用主题应用它,方法是在主应用样式中将其设置为 bottomSheetDialogTheme
:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="bottomSheetDialogTheme">@style/MyBottomSheetStyle</item>
</style>
或覆盖底部的 getTheme()
-sheet class.
override fun getTheme(): Int = R.style.MyBottomSheetStyle
如果选择第二个,最好使用基数 class 并在其上实现 getTheme()
。
最近我改用 com.google.android.material:material:1.0.0
作为应用主题。
除了设置colorPrimary
、colorPrimaryDark
和colorAccent
并使用MaterialButton
和Widget.MaterialComponents.Button
样式外,activity/fragment和bottomSheetFragment中的按钮颜色不一样!
在 Activity/Fragment 中可以。但在 BottomSheet 中有不同的颜色(绿色)。
为 BottomSheetDialogFragment 定义新样式:
<style name="MyBottomSheetStyle" 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>
您可以通过应用主题应用它,方法是在主应用样式中将其设置为 bottomSheetDialogTheme
:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="bottomSheetDialogTheme">@style/MyBottomSheetStyle</item>
</style>
或覆盖底部的 getTheme()
-sheet class.
override fun getTheme(): Int = R.style.MyBottomSheetStyle
如果选择第二个,最好使用基数 class 并在其上实现 getTheme()
。