Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BottomSheet style after using MaterialComponents Theme

Recently I switched to using com.google.android.material:material:1.0.0 for app theme.

In addition to set colorPrimary,colorPrimaryDark and colorAccent and using MaterialButton with Widget.MaterialComponents.Button style, buttons in activity/fragment and bottomSheetFragment are different in colors!

in Activity/Fragment is OK. but in BottomSheet has a different color (green).

enter image description here

like image 647
beigirad Avatar asked Mar 04 '23 08:03

beigirad


1 Answers

Define a new style for 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>

You can apply it via app theme by setting it as bottomSheetDialogTheme in main app style:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    ...

    <item name="bottomSheetDialogTheme">@style/MyBottomSheetStyle</item>
</style>

or override getTheme() of in your bottom-sheet class.

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

If you choose second one, It's better to use a base class and implement getTheme() on it.

like image 162
beigirad Avatar answered Mar 19 '23 00:03

beigirad