question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

App Theme does not get applied to BottomSheetDialogFragment

See original GitHub issue

Problem

The App Theme does not get appplied when using BottomSheetDialogFragment.

Reproduction steps

  • Like advised, I extended 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)
    }
}
  • Also, like advised, I use this code to show the Dialog:
    LoginSheet().showNow(fragmentManager, "LoginDialog")
  • The BottomSheet shows up without the desired theme.

Version number

  • 1.0.0-alpha1

Operating system and device

  • Android 8.1 (AOSP) on OnePlus One

Related issues

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:16
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

31reactions
Bloody-Badboycommented, May 19, 2018

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)
  }
9reactions
DSteve595commented, Nov 25, 2018

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>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my BottomSheetDialogFragment ignoring my app ...
My app uses a dark theme, and the BottomSheetDialogFragment displays with a white background and doesn't use the accent color of my app....
Read more >
Sheets: bottom - Material Design
BottomSheetDialogFragment is a subclass of AppCompatFragment, which means you need to use Activity.getSupportFragmentManager(). Note: Don't call ...
Read more >
Show rounded corners for BottomSheetDialogFragment
Create custom BottomSheetDialogFragment for rounded corners as RoundedBottomSheetDialogFragment.kt ... Dialog = BottomSheetDialog(requireContext(), theme)
Read more >
Using DialogFragment | CodePath Android Cliffnotes
Overview. DialogFragment is a specialized Fragment used when you want to display an overlay modal window within an activity that floats on top...
Read more >
Customizing your bottom sheet's corners - Bryan Herbst
App -wide bottom sheet dialog theme. If you only want to shape your bottom sheet dialogs (both BottomSheetDialog and BottomSheetDialogFragment ), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found