Closed beatbrot closed 5 years ago
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’s 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?
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) }
How can I use this with view binding?
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) }
How can I use this with view binding?
val contextThemeWrapper =
ContextThemeWrapper(activity, R.style.Theme_MeroBazar) // your app theme here
val view = inflater.cloneInContext(contextThemeWrapper)
.inflate(R.layout.bs_edit_product, container, false)
_binding = EditProductBinding.bind(view)
return binding.root
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) }
@subashz @Bloody-Badboy this solution does not work for me. The theme doesn't change in darkmode. My AppTheme
extends Theme.AppCompat.DayNight
. I am using BottomSheetDialogFragment
from com.google.android.material.bottomsheet.BottomSheetDialogFragment
.
These are my dependencies for appcompat and material
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0-alpha02'
Any idea as to where I could be going wrong?
Problem
The App Theme does not get appplied when using
BottomSheetDialogFragment
.Reproduction steps
Like advised, I extended
BottomSheetDialogFragment
like so:Also, like advised, I use this code to show the Dialog:
The BottomSheet shows up without the desired theme.
Version number
Operating system and device
Related issues