bei*_*rad 4 android android-styles material-design bottom-sheet material-components-android
最近我切换到使用com.google.android.material:material:1.0.0应用程序主题。
除了 set colorPrimary, colorPrimaryDarkand colorAccentusing MaterialButtonwith Widget.MaterialComponents.Buttonstyle 之外,activity/fragment和bottomSheetFragment中的按钮颜色不同!
在活动/片段中是可以的。但在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>
Run Code Online (Sandbox Code Playgroud)
您可以通过应用程序主题将其设置bottomSheetDialogTheme为主应用程序样式来应用它:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="bottomSheetDialogTheme">@style/MyBottomSheetStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
或覆盖getTheme()在您的底部表类中。
override fun getTheme(): Int = R.style.MyBottomSheetStyle
Run Code Online (Sandbox Code Playgroud)
如果选择第二个,最好使用基类并getTheme()在其上实现。