The App Theme does not get appplied when using BottomSheetDialogFragment.
BottomSheetDialogFragment like so:class LoginSheet : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.login_sheet, container, false)
}
}
LoginSheet().showNow(fragmentManager, "LoginDialog")
The BottomSheet shows up without the desired theme.
Use it like this to apply the AppTheme
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val contextThemeWrapper = ContextThemeWrapper(activity, R.style.AppTheme) // your app theme here
return inflater.cloneInContext(contextThemeWrapper).inflate(R.layout.login_sheet, container, false)
}
This is happening because the default bottomSheetDialogTheme attribute points to a style that isn't a ThemeOverlay, but rather a full theme that defines the default colors and such. This should be fixed in the library IMO.
Here's a somewhat clean workaround:
<style name="Theme.YourApp" parent="Theme.MaterialComponents.*something*">
...
<item name="bottomSheetDialogTheme">@style/ThemeOverlay.YourApp.BottomSheetDialog</item>
...
</style>
<style name="ThemeOverlay.YourApp.BottomSheetDialog" parent="ThemeOverlay.MaterialComponents.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowAnimationStyle">@style/Animation.MaterialComponents.BottomSheetDialog</item>
<item name="bottomSheetStyle">@style/Widget.MaterialComponents.BottomSheet.Modal</item>
</style>
I've added a bug to track this issue: https://issuetracker.google.com/issues/120073616
I can confirm that this fixes the theming issue. @DSteve595 would you like me to submit a pull request on your behalf?
A pull request would be great, but I'm not familiar enough with the structure of the styles.xml to be confident in doing it properly.
Please comment on the bug with any other updates.
@ymarian Is this fixed? Or is the tracking being moved to https://issuetracker.google.com/issues/120073616?
@DSteve595 just the latter but it鈥檚 one of our priorities now. Hopefully syncing a fix soon. I can comment again here when that happens
Awesome, thank you so much!
Has ThemeOverlay.MaterialComponents.BottomSheetDialog been removed since this issue?
Most helpful comment
Use it like this to apply the AppTheme