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.

BottomSheetDialogFragment bottom navigation color

See original GitHub issue

I have tried to apply a custom color to the bottom navigation bar but failed. I tried this:

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:navigationBarColor">@color/white</item>
<item name="android:windowTranslucentNavigation">false</item>

It works for usual DialogFragment but not for the BottomSheetDialogFragment.

I tried this also:

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
        dialog.setOnShowListener { dialogInterface ->
            val d = dialogInterface as BottomSheetDialog
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                d.window?.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
                d.window?.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
                d.window?.navigationBarColor = ContextCompat.getColor(requireContext(), R.color.white)
            }
        }

        return dialog 
}

How can I change the nagivation bar color to custom? Right now it is always transparent.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:20
  • Comments:13

github_iconTop GitHub Comments

62reactions
ivaniskandarcommented, Sep 5, 2019

My solution for this is by having my own bottom sheet style and applying it by overriding the getTheme() method:

    <style name="Widget.AppTheme.BottomSheet" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
        <item name="android:windowIsFloating">false</item> <!-- This is important -->
        <item name="android:statusBarColor">@color/transparent</item> <!-- And then this will be needed -->
        <item name="android:navigationBarColor">@color/bottom_sheet_background</item>
        <item name="android:colorBackground">@color/bottom_sheet_background</item>
    </style>

I’m yet to try making the navbar transparent and making the actual bottom sheet draws under the navbar, but that one is working for now.

5reactions
stephentalleycommented, Oct 15, 2020

There’s no need to override an entire theme, or change any of your Java/Kotlin code. Just set the appropriate theme overlay in your app theme:

<style
    name="MyAppTheme"
    parent="Theme.MaterialComponents.DayNight"
>
    …
    <item name="bottomSheetDialogTheme">@style/MyAppBottomSheetDialog</item>
    …
</style>

<style
    name="MyAppBottomSheetDialog"
    parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog"
>
    <item name="android:windowIsFloating">false</item>
</style>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent BottomSheetDialogFragment covering navigation bar
Nothing changes: neither the navigation bar color nor the style of the bottom sheet widget. Any hints of what might I be doing...
Read more >
Show BottomSheetDialogFragment changes status bar color ...
I think the BottomSheetDialogFragment should not change the status bar color to black as this somehow effects the style of the app. I...
Read more >
Bottom Sheet Above Bottom Navigation | by Narayan Panthi
Bottom Sheet Above Bottom Navigation. Show BottomSheetDialog above the BottomNavigation in android. ... android:background="@android:color/transparent">
Read more >
Android bottom sheet behind navigation bar
Android bottom sheet behind navigation bar · Transparent background for BottomSheetDialogFragment · Bottom sheet background color · Custom bottom sheet dialog ...
Read more >
BottomSheetDialogFragment - Android Developers
This is a version of DialogFragment that shows a bottom sheet using BottomSheetDialog instead of a floating dialog. Summary. Inherited constants.
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