android_dev
android_dev

Reputation: 4188

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?

Upvotes: 9

Views: 6915

Answers (2)

Tamás Szincsák
Tamás Szincsák

Reputation: 1031

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>

Upvotes: 27

Vlastimil Eli&#225;š
Vlastimil Eli&#225;š

Reputation: 21

I just hit this problem. I used attribute you mentioned in the root layout of the dialog and it helped me.

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

Upvotes: 2

Related Questions