Search code examples
androidandroid-support-libraryandroid-theme

BottomSheetDialogFragment sets wrong background color for Dark theme


I have recently added BottomSheetDialogFragment to my app, but it shows background color for Material Dark theme as white. Even when I use

android:background="?android:attr/colorBackground"

for the root layout of the dialog, it is still white (but this attr is ok outside of the dialog). Has anyone ever had this problem?


Solution

  • The appearance of a bottom sheet dialog is controlled by an attribute named bottomSheetDialogTheme, which defaults to Theme.Design.Light.BottomSheetDialog. To achieve a dark background (and also white text, properly colored controls, etc.), you need to override it in your activity theme:

    <style name="YourActivityTheme" parent="...">
        <!-- ... -->
    
        <item name="bottomSheetDialogTheme">@style/Theme.Design.BottomSheetDialog</item>
    </style>