Prevent BottomSheetDialogFragment covering navigation bar











up vote
15
down vote

favorite
3












I'm using really naive code to show a bottom sheet dialog fragment:



class LogoutBottomSheetFragment : BottomSheetDialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
return view
}
}


This is how I called this dialog:



LogoutBottomSheetFragment().show(supportFragmentManager, "logout")


But I get this horrible shown in the image below.
How can I keep the navigation bar white (the bottom bar where the back/home software buttons are)?





App Theme I'm using:



 <!-- Base application theme. -->
<style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style

<style name="AppTheme" parent="BaseAppTheme">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>

<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@android:color/white</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/charcoal_grey</item>

<item name="colorControlNormal">@color/charcoal_grey</item>
<item name="colorControlActivated">@color/charcoal_grey</item>
<item name="colorControlHighlight">@color/charcoal_grey</item>

<item name="android:textColorPrimary">@color/charcoal_grey</item>
<item name="android:textColor">@color/charcoal_grey</item>

<item name="android:windowBackground">@color/white</item>
</style>


I've also tried to override the setupDialog instead of the onCreateView, but still happens:



    @SuppressLint("RestrictedApi")
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
val view = View.inflate(context, R.layout. view_image_source_chooser,null)
dialog.setContentView(view)
}









share|improve this question
























  • Are you sure that it is attached to your CoordinatorLayout ?
    – JJ86
    Dec 4 '17 at 10:25










  • How do you show the fragment?
    – kalabalik
    Dec 4 '17 at 10:33










  • @JJ86 yes the activity root is Coordinator layout, though i doubt if it has any effect on this issue as this is a dialog fragment.
    – oferiko
    Dec 4 '17 at 12:09












  • @KalaBalik updated my question
    – oferiko
    Dec 4 '17 at 12:10










  • Can you share styles.xml, specifically the theme of the Activity?
    – azizbekian
    Dec 4 '17 at 12:39















up vote
15
down vote

favorite
3












I'm using really naive code to show a bottom sheet dialog fragment:



class LogoutBottomSheetFragment : BottomSheetDialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
return view
}
}


This is how I called this dialog:



LogoutBottomSheetFragment().show(supportFragmentManager, "logout")


But I get this horrible shown in the image below.
How can I keep the navigation bar white (the bottom bar where the back/home software buttons are)?





App Theme I'm using:



 <!-- Base application theme. -->
<style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style

<style name="AppTheme" parent="BaseAppTheme">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>

<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@android:color/white</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/charcoal_grey</item>

<item name="colorControlNormal">@color/charcoal_grey</item>
<item name="colorControlActivated">@color/charcoal_grey</item>
<item name="colorControlHighlight">@color/charcoal_grey</item>

<item name="android:textColorPrimary">@color/charcoal_grey</item>
<item name="android:textColor">@color/charcoal_grey</item>

<item name="android:windowBackground">@color/white</item>
</style>


I've also tried to override the setupDialog instead of the onCreateView, but still happens:



    @SuppressLint("RestrictedApi")
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
val view = View.inflate(context, R.layout. view_image_source_chooser,null)
dialog.setContentView(view)
}









share|improve this question
























  • Are you sure that it is attached to your CoordinatorLayout ?
    – JJ86
    Dec 4 '17 at 10:25










  • How do you show the fragment?
    – kalabalik
    Dec 4 '17 at 10:33










  • @JJ86 yes the activity root is Coordinator layout, though i doubt if it has any effect on this issue as this is a dialog fragment.
    – oferiko
    Dec 4 '17 at 12:09












  • @KalaBalik updated my question
    – oferiko
    Dec 4 '17 at 12:10










  • Can you share styles.xml, specifically the theme of the Activity?
    – azizbekian
    Dec 4 '17 at 12:39













up vote
15
down vote

favorite
3









up vote
15
down vote

favorite
3






3





I'm using really naive code to show a bottom sheet dialog fragment:



class LogoutBottomSheetFragment : BottomSheetDialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
return view
}
}


This is how I called this dialog:



LogoutBottomSheetFragment().show(supportFragmentManager, "logout")


But I get this horrible shown in the image below.
How can I keep the navigation bar white (the bottom bar where the back/home software buttons are)?





App Theme I'm using:



 <!-- Base application theme. -->
<style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style

<style name="AppTheme" parent="BaseAppTheme">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>

<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@android:color/white</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/charcoal_grey</item>

<item name="colorControlNormal">@color/charcoal_grey</item>
<item name="colorControlActivated">@color/charcoal_grey</item>
<item name="colorControlHighlight">@color/charcoal_grey</item>

<item name="android:textColorPrimary">@color/charcoal_grey</item>
<item name="android:textColor">@color/charcoal_grey</item>

<item name="android:windowBackground">@color/white</item>
</style>


I've also tried to override the setupDialog instead of the onCreateView, but still happens:



    @SuppressLint("RestrictedApi")
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
val view = View.inflate(context, R.layout. view_image_source_chooser,null)
dialog.setContentView(view)
}









share|improve this question















I'm using really naive code to show a bottom sheet dialog fragment:



class LogoutBottomSheetFragment : BottomSheetDialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
return view
}
}


This is how I called this dialog:



LogoutBottomSheetFragment().show(supportFragmentManager, "logout")


But I get this horrible shown in the image below.
How can I keep the navigation bar white (the bottom bar where the back/home software buttons are)?





App Theme I'm using:



 <!-- Base application theme. -->
<style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style

<style name="AppTheme" parent="BaseAppTheme">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>

<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@android:color/white</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/charcoal_grey</item>

<item name="colorControlNormal">@color/charcoal_grey</item>
<item name="colorControlActivated">@color/charcoal_grey</item>
<item name="colorControlHighlight">@color/charcoal_grey</item>

<item name="android:textColorPrimary">@color/charcoal_grey</item>
<item name="android:textColor">@color/charcoal_grey</item>

<item name="android:windowBackground">@color/white</item>
</style>


I've also tried to override the setupDialog instead of the onCreateView, but still happens:



    @SuppressLint("RestrictedApi")
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
val view = View.inflate(context, R.layout. view_image_source_chooser,null)
dialog.setContentView(view)
}






android android-layout android-view navigationbar bottom-sheet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 5 '17 at 12:31

























asked Nov 29 '17 at 13:25









oferiko

6091817




6091817












  • Are you sure that it is attached to your CoordinatorLayout ?
    – JJ86
    Dec 4 '17 at 10:25










  • How do you show the fragment?
    – kalabalik
    Dec 4 '17 at 10:33










  • @JJ86 yes the activity root is Coordinator layout, though i doubt if it has any effect on this issue as this is a dialog fragment.
    – oferiko
    Dec 4 '17 at 12:09












  • @KalaBalik updated my question
    – oferiko
    Dec 4 '17 at 12:10










  • Can you share styles.xml, specifically the theme of the Activity?
    – azizbekian
    Dec 4 '17 at 12:39


















  • Are you sure that it is attached to your CoordinatorLayout ?
    – JJ86
    Dec 4 '17 at 10:25










  • How do you show the fragment?
    – kalabalik
    Dec 4 '17 at 10:33










  • @JJ86 yes the activity root is Coordinator layout, though i doubt if it has any effect on this issue as this is a dialog fragment.
    – oferiko
    Dec 4 '17 at 12:09












  • @KalaBalik updated my question
    – oferiko
    Dec 4 '17 at 12:10










  • Can you share styles.xml, specifically the theme of the Activity?
    – azizbekian
    Dec 4 '17 at 12:39
















Are you sure that it is attached to your CoordinatorLayout ?
– JJ86
Dec 4 '17 at 10:25




Are you sure that it is attached to your CoordinatorLayout ?
– JJ86
Dec 4 '17 at 10:25












How do you show the fragment?
– kalabalik
Dec 4 '17 at 10:33




How do you show the fragment?
– kalabalik
Dec 4 '17 at 10:33












@JJ86 yes the activity root is Coordinator layout, though i doubt if it has any effect on this issue as this is a dialog fragment.
– oferiko
Dec 4 '17 at 12:09






@JJ86 yes the activity root is Coordinator layout, though i doubt if it has any effect on this issue as this is a dialog fragment.
– oferiko
Dec 4 '17 at 12:09














@KalaBalik updated my question
– oferiko
Dec 4 '17 at 12:10




@KalaBalik updated my question
– oferiko
Dec 4 '17 at 12:10












Can you share styles.xml, specifically the theme of the Activity?
– azizbekian
Dec 4 '17 at 12:39




Can you share styles.xml, specifically the theme of the Activity?
– azizbekian
Dec 4 '17 at 12:39












6 Answers
6






active

oldest

votes

















up vote
4
down vote













I had the same problem and I finally found a solution which is not hacky or needs an orbitant amount of code.



This Method replaced the window background with a LayerDrawable which consists of two elements: the background dim and the navigation bar background.



@RequiresApi(api = Build.VERSION_CODES.M)
private void setWhiteNavigationBar(@NonNull Dialog dialog) {
Window window = dialog.getWindow();
if (window != null) {
DisplayMetrics metrics = new DisplayMetrics();
window.getWindowManager().getDefaultDisplay().getMetrics(metrics);

GradientDrawable dimDrawable = new GradientDrawable();
// ...customize your dim effect here

GradientDrawable navigationBarDrawable = new GradientDrawable();
navigationBarDrawable.setShape(GradientDrawable.RECTANGLE);
navigationBarDrawable.setColor(Color.WHITE);

Drawable layers = {dimDrawable, navigationBarDrawable};

LayerDrawable windowBackground = new LayerDrawable(layers);
windowBackground.setLayerInsetTop(1, metrics.heightPixels);

window.setBackgroundDrawable(windowBackground);
}
}


The method "setLayerInsetTop" requieres the API 23 but thats fine because dark navigation bar icons were introduced in Android O (API 26).



So the last part of the solution is to call this method from your bottom sheets onCreate method like this.



@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setWhiteNavigationBar(dialog);
}

return dialog;
}


I hope it helps and please let me know if you find a device or case in which this solution does not work.



before and after






share|improve this answer























  • Hey may be its not context but can you tell me how do round corners for BottomSheetDialog
    – Hemanth S Tobi
    Jul 27 at 3:14






  • 1




    It is pretty simple: you have to override the bottomSheetTheme in your App theme and in your bottomSheetTheme the bottomSheetStyle. In your bottomSheetStyle you can now set the background to a drawable with a rectangle shape and corners. That's it.
    – Denis Schura
    Jul 27 at 9:11


















up vote
1
down vote













Answer from j2esu works pretty well. However if you insist on 'completely white' navigation bar you have to omit part of it.



Please note that this solution is applicable from Android O (API 26) since dark navigation bar icons were introduced in this version. On older versions you would get white icons on white background.



You need to:




  1. Add android:fitsSystemWindows="true" to root of your dialog layout.

  2. Modify Window of your Dialog properly.


Place this code to onStart of your child of BottomSheetDialogFragment. If you are using design library instead of material library use android.support.design.R.id.container.



@Override
public void onStart() {
super.onStart();
if (getDialog() != null && getDialog().getWindow() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Window window = getDialog().getWindow();
window.findViewById(com.google.android.material.R.id.container).setFitsSystemWindows(false);
// dark navigation bar icons
View decorView = window.getDecorView();
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
}


Result might look like this:



White navigation bar on Android P in dialog






share|improve this answer




























    up vote
    0
    down vote













    BottomSheetDialogFragment extends DialogFragment. Inside BottomSheetDialog it's creating a Dialog inside onCreateDialog



    public class BottomSheetDialogFragment extends AppCompatDialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new BottomSheetDialog(getContext(), getTheme());
    }

    }


    The dim layer is a property of dialog which is applying to whole window. Then only it will cover the status bar. If you need dim layer without bottom buttons, then you have to do manually by showing a layer inside layout and changing status bar colour accordingly.



    Apply theme for dialogfragment as given below



    class LogoutBottomSheetFragment : BottomSheetDialogFragment() {
    init {
    setStyle(DialogFragment.STYLE_NORMAL,R.style.dialog);
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
    return view
    }


    }


    With styles as



     <style name="dialog" parent="Base.Theme.AppCompat.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">false</item>
    </style>





    share|improve this answer























    • ...then you have to do manually by showing a layer inside layout and changing status bar colour accordingly How? Isn't that the question? Your answer looks incomplete.
      – azizbekian
      Dec 10 '17 at 10:03










    • @azizbekian Check whether that dim is gone in your phone by using style specified in answer. I don't have that kind of phone to test with
      – Sangeet Suresh
      Dec 10 '17 at 10:42


















    up vote
    0
    down vote













    In BottomSheetDialogFragment, the only thing that needs to be done is to set the container of the underlying CoordinatorLayout fitSystemWindows to false.



    override fun onActivityCreated(savedInstanceState: Bundle?) {
    super.onActivityCreated(savedInstanceState)
    (view!!.parent.parent.parent as View).fitsSystemWindows = false
    }




    • view is your layout


    • view.parent is a FrameLayout containing your view


    • view.parent.parent is the CoordinatorLayout


    • view.parent.parent.parent is the container for CoordinatorLayout which has its fitsSystemWindow set to true by default.


    This ensures that the whole BottomSheetDialogFragment is drawn underneath the navigation bar. Then you can set the fitsSystemWindows to your own containers accordingly.



    What you don't need from the other answers in particular is:




    • hacky findViewById with reference to system ids, which are subject to change,

    • reference to getWindow() or getDialog(),

    • no drawables to be set in the place of navigation bar.


    This solution works with BottomSheetDialogFragment created with onCreateView, I did not check onCreateDialog.






    share|improve this answer




























      up vote
      -1
      down vote













      Don't use BottomSheetDialogFragment.I would prefer use adding bottom sheet by wrapping the layout in the coordinator layout and attaching BottomSheetBehaiviour to that layout



      You can follow this as an example






      share|improve this answer





















      • I would like to have the dim effect without writing this code myself. This will be my last resort if I will not find a fix for this issue
        – oferiko
        Dec 9 '17 at 17:55










      • It is not possible because opening a dialog pauses the current activity so you won't be able have any interaction with the activity
        – Farmaan Elahi
        Dec 9 '17 at 17:58


















      up vote
      -1
      down vote













      I had the same problem. After looking into sources I found a workaround (a little bit hacky, but I found no alternatives).



      public class YourDialog extends BottomSheetDialogFragment {

      //your code

      @NonNull
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
      return new FitSystemWindowsBottomSheetDialog(getContext());
      }
      }

      public class FitSystemWindowsBottomSheetDialog extends BottomSheetDialog {

      public FitSystemWindowsBottomSheetDialog(Context context) {
      super(context);
      }

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      if (getWindow() != null && Build.VERSION.SDK_INT >= 21) {
      findViewById(android.support.design.R.id.coordinator).setFitsSystemWindows(false);
      findViewById(android.support.design.R.id.container).setFitsSystemWindows(false);
      getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
      WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
      }
      }
      }


      And, finally, don't forget to add android:fitsSystemWindows="true" at the root of your dialog layout.



      Hope it helps.






      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47553936%2fprevent-bottomsheetdialogfragment-covering-navigation-bar%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        4
        down vote













        I had the same problem and I finally found a solution which is not hacky or needs an orbitant amount of code.



        This Method replaced the window background with a LayerDrawable which consists of two elements: the background dim and the navigation bar background.



        @RequiresApi(api = Build.VERSION_CODES.M)
        private void setWhiteNavigationBar(@NonNull Dialog dialog) {
        Window window = dialog.getWindow();
        if (window != null) {
        DisplayMetrics metrics = new DisplayMetrics();
        window.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        GradientDrawable dimDrawable = new GradientDrawable();
        // ...customize your dim effect here

        GradientDrawable navigationBarDrawable = new GradientDrawable();
        navigationBarDrawable.setShape(GradientDrawable.RECTANGLE);
        navigationBarDrawable.setColor(Color.WHITE);

        Drawable layers = {dimDrawable, navigationBarDrawable};

        LayerDrawable windowBackground = new LayerDrawable(layers);
        windowBackground.setLayerInsetTop(1, metrics.heightPixels);

        window.setBackgroundDrawable(windowBackground);
        }
        }


        The method "setLayerInsetTop" requieres the API 23 but thats fine because dark navigation bar icons were introduced in Android O (API 26).



        So the last part of the solution is to call this method from your bottom sheets onCreate method like this.



        @NonNull
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        setWhiteNavigationBar(dialog);
        }

        return dialog;
        }


        I hope it helps and please let me know if you find a device or case in which this solution does not work.



        before and after






        share|improve this answer























        • Hey may be its not context but can you tell me how do round corners for BottomSheetDialog
          – Hemanth S Tobi
          Jul 27 at 3:14






        • 1




          It is pretty simple: you have to override the bottomSheetTheme in your App theme and in your bottomSheetTheme the bottomSheetStyle. In your bottomSheetStyle you can now set the background to a drawable with a rectangle shape and corners. That's it.
          – Denis Schura
          Jul 27 at 9:11















        up vote
        4
        down vote













        I had the same problem and I finally found a solution which is not hacky or needs an orbitant amount of code.



        This Method replaced the window background with a LayerDrawable which consists of two elements: the background dim and the navigation bar background.



        @RequiresApi(api = Build.VERSION_CODES.M)
        private void setWhiteNavigationBar(@NonNull Dialog dialog) {
        Window window = dialog.getWindow();
        if (window != null) {
        DisplayMetrics metrics = new DisplayMetrics();
        window.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        GradientDrawable dimDrawable = new GradientDrawable();
        // ...customize your dim effect here

        GradientDrawable navigationBarDrawable = new GradientDrawable();
        navigationBarDrawable.setShape(GradientDrawable.RECTANGLE);
        navigationBarDrawable.setColor(Color.WHITE);

        Drawable layers = {dimDrawable, navigationBarDrawable};

        LayerDrawable windowBackground = new LayerDrawable(layers);
        windowBackground.setLayerInsetTop(1, metrics.heightPixels);

        window.setBackgroundDrawable(windowBackground);
        }
        }


        The method "setLayerInsetTop" requieres the API 23 but thats fine because dark navigation bar icons were introduced in Android O (API 26).



        So the last part of the solution is to call this method from your bottom sheets onCreate method like this.



        @NonNull
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        setWhiteNavigationBar(dialog);
        }

        return dialog;
        }


        I hope it helps and please let me know if you find a device or case in which this solution does not work.



        before and after






        share|improve this answer























        • Hey may be its not context but can you tell me how do round corners for BottomSheetDialog
          – Hemanth S Tobi
          Jul 27 at 3:14






        • 1




          It is pretty simple: you have to override the bottomSheetTheme in your App theme and in your bottomSheetTheme the bottomSheetStyle. In your bottomSheetStyle you can now set the background to a drawable with a rectangle shape and corners. That's it.
          – Denis Schura
          Jul 27 at 9:11













        up vote
        4
        down vote










        up vote
        4
        down vote









        I had the same problem and I finally found a solution which is not hacky or needs an orbitant amount of code.



        This Method replaced the window background with a LayerDrawable which consists of two elements: the background dim and the navigation bar background.



        @RequiresApi(api = Build.VERSION_CODES.M)
        private void setWhiteNavigationBar(@NonNull Dialog dialog) {
        Window window = dialog.getWindow();
        if (window != null) {
        DisplayMetrics metrics = new DisplayMetrics();
        window.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        GradientDrawable dimDrawable = new GradientDrawable();
        // ...customize your dim effect here

        GradientDrawable navigationBarDrawable = new GradientDrawable();
        navigationBarDrawable.setShape(GradientDrawable.RECTANGLE);
        navigationBarDrawable.setColor(Color.WHITE);

        Drawable layers = {dimDrawable, navigationBarDrawable};

        LayerDrawable windowBackground = new LayerDrawable(layers);
        windowBackground.setLayerInsetTop(1, metrics.heightPixels);

        window.setBackgroundDrawable(windowBackground);
        }
        }


        The method "setLayerInsetTop" requieres the API 23 but thats fine because dark navigation bar icons were introduced in Android O (API 26).



        So the last part of the solution is to call this method from your bottom sheets onCreate method like this.



        @NonNull
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        setWhiteNavigationBar(dialog);
        }

        return dialog;
        }


        I hope it helps and please let me know if you find a device or case in which this solution does not work.



        before and after






        share|improve this answer














        I had the same problem and I finally found a solution which is not hacky or needs an orbitant amount of code.



        This Method replaced the window background with a LayerDrawable which consists of two elements: the background dim and the navigation bar background.



        @RequiresApi(api = Build.VERSION_CODES.M)
        private void setWhiteNavigationBar(@NonNull Dialog dialog) {
        Window window = dialog.getWindow();
        if (window != null) {
        DisplayMetrics metrics = new DisplayMetrics();
        window.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        GradientDrawable dimDrawable = new GradientDrawable();
        // ...customize your dim effect here

        GradientDrawable navigationBarDrawable = new GradientDrawable();
        navigationBarDrawable.setShape(GradientDrawable.RECTANGLE);
        navigationBarDrawable.setColor(Color.WHITE);

        Drawable layers = {dimDrawable, navigationBarDrawable};

        LayerDrawable windowBackground = new LayerDrawable(layers);
        windowBackground.setLayerInsetTop(1, metrics.heightPixels);

        window.setBackgroundDrawable(windowBackground);
        }
        }


        The method "setLayerInsetTop" requieres the API 23 but thats fine because dark navigation bar icons were introduced in Android O (API 26).



        So the last part of the solution is to call this method from your bottom sheets onCreate method like this.



        @NonNull
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        setWhiteNavigationBar(dialog);
        }

        return dialog;
        }


        I hope it helps and please let me know if you find a device or case in which this solution does not work.



        before and after







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jul 13 at 16:15

























        answered Jul 13 at 16:03









        Denis Schura

        1367




        1367












        • Hey may be its not context but can you tell me how do round corners for BottomSheetDialog
          – Hemanth S Tobi
          Jul 27 at 3:14






        • 1




          It is pretty simple: you have to override the bottomSheetTheme in your App theme and in your bottomSheetTheme the bottomSheetStyle. In your bottomSheetStyle you can now set the background to a drawable with a rectangle shape and corners. That's it.
          – Denis Schura
          Jul 27 at 9:11


















        • Hey may be its not context but can you tell me how do round corners for BottomSheetDialog
          – Hemanth S Tobi
          Jul 27 at 3:14






        • 1




          It is pretty simple: you have to override the bottomSheetTheme in your App theme and in your bottomSheetTheme the bottomSheetStyle. In your bottomSheetStyle you can now set the background to a drawable with a rectangle shape and corners. That's it.
          – Denis Schura
          Jul 27 at 9:11
















        Hey may be its not context but can you tell me how do round corners for BottomSheetDialog
        – Hemanth S Tobi
        Jul 27 at 3:14




        Hey may be its not context but can you tell me how do round corners for BottomSheetDialog
        – Hemanth S Tobi
        Jul 27 at 3:14




        1




        1




        It is pretty simple: you have to override the bottomSheetTheme in your App theme and in your bottomSheetTheme the bottomSheetStyle. In your bottomSheetStyle you can now set the background to a drawable with a rectangle shape and corners. That's it.
        – Denis Schura
        Jul 27 at 9:11




        It is pretty simple: you have to override the bottomSheetTheme in your App theme and in your bottomSheetTheme the bottomSheetStyle. In your bottomSheetStyle you can now set the background to a drawable with a rectangle shape and corners. That's it.
        – Denis Schura
        Jul 27 at 9:11












        up vote
        1
        down vote













        Answer from j2esu works pretty well. However if you insist on 'completely white' navigation bar you have to omit part of it.



        Please note that this solution is applicable from Android O (API 26) since dark navigation bar icons were introduced in this version. On older versions you would get white icons on white background.



        You need to:




        1. Add android:fitsSystemWindows="true" to root of your dialog layout.

        2. Modify Window of your Dialog properly.


        Place this code to onStart of your child of BottomSheetDialogFragment. If you are using design library instead of material library use android.support.design.R.id.container.



        @Override
        public void onStart() {
        super.onStart();
        if (getDialog() != null && getDialog().getWindow() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Window window = getDialog().getWindow();
        window.findViewById(com.google.android.material.R.id.container).setFitsSystemWindows(false);
        // dark navigation bar icons
        View decorView = window.getDecorView();
        decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
        }
        }


        Result might look like this:



        White navigation bar on Android P in dialog






        share|improve this answer

























          up vote
          1
          down vote













          Answer from j2esu works pretty well. However if you insist on 'completely white' navigation bar you have to omit part of it.



          Please note that this solution is applicable from Android O (API 26) since dark navigation bar icons were introduced in this version. On older versions you would get white icons on white background.



          You need to:




          1. Add android:fitsSystemWindows="true" to root of your dialog layout.

          2. Modify Window of your Dialog properly.


          Place this code to onStart of your child of BottomSheetDialogFragment. If you are using design library instead of material library use android.support.design.R.id.container.



          @Override
          public void onStart() {
          super.onStart();
          if (getDialog() != null && getDialog().getWindow() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          Window window = getDialog().getWindow();
          window.findViewById(com.google.android.material.R.id.container).setFitsSystemWindows(false);
          // dark navigation bar icons
          View decorView = window.getDecorView();
          decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
          }
          }


          Result might look like this:



          White navigation bar on Android P in dialog






          share|improve this answer























            up vote
            1
            down vote










            up vote
            1
            down vote









            Answer from j2esu works pretty well. However if you insist on 'completely white' navigation bar you have to omit part of it.



            Please note that this solution is applicable from Android O (API 26) since dark navigation bar icons were introduced in this version. On older versions you would get white icons on white background.



            You need to:




            1. Add android:fitsSystemWindows="true" to root of your dialog layout.

            2. Modify Window of your Dialog properly.


            Place this code to onStart of your child of BottomSheetDialogFragment. If you are using design library instead of material library use android.support.design.R.id.container.



            @Override
            public void onStart() {
            super.onStart();
            if (getDialog() != null && getDialog().getWindow() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            Window window = getDialog().getWindow();
            window.findViewById(com.google.android.material.R.id.container).setFitsSystemWindows(false);
            // dark navigation bar icons
            View decorView = window.getDecorView();
            decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
            }
            }


            Result might look like this:



            White navigation bar on Android P in dialog






            share|improve this answer












            Answer from j2esu works pretty well. However if you insist on 'completely white' navigation bar you have to omit part of it.



            Please note that this solution is applicable from Android O (API 26) since dark navigation bar icons were introduced in this version. On older versions you would get white icons on white background.



            You need to:




            1. Add android:fitsSystemWindows="true" to root of your dialog layout.

            2. Modify Window of your Dialog properly.


            Place this code to onStart of your child of BottomSheetDialogFragment. If you are using design library instead of material library use android.support.design.R.id.container.



            @Override
            public void onStart() {
            super.onStart();
            if (getDialog() != null && getDialog().getWindow() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            Window window = getDialog().getWindow();
            window.findViewById(com.google.android.material.R.id.container).setFitsSystemWindows(false);
            // dark navigation bar icons
            View decorView = window.getDecorView();
            decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
            }
            }


            Result might look like this:



            White navigation bar on Android P in dialog







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 30 at 22:30









            mroczis

            9591913




            9591913






















                up vote
                0
                down vote













                BottomSheetDialogFragment extends DialogFragment. Inside BottomSheetDialog it's creating a Dialog inside onCreateDialog



                public class BottomSheetDialogFragment extends AppCompatDialogFragment {

                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                return new BottomSheetDialog(getContext(), getTheme());
                }

                }


                The dim layer is a property of dialog which is applying to whole window. Then only it will cover the status bar. If you need dim layer without bottom buttons, then you have to do manually by showing a layer inside layout and changing status bar colour accordingly.



                Apply theme for dialogfragment as given below



                class LogoutBottomSheetFragment : BottomSheetDialogFragment() {
                init {
                setStyle(DialogFragment.STYLE_NORMAL,R.style.dialog);
                }

                override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
                val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
                return view
                }


                }


                With styles as



                 <style name="dialog" parent="Base.Theme.AppCompat.Dialog">
                <item name="android:windowBackground">@android:color/transparent</item>
                <item name="android:backgroundDimEnabled">false</item>
                </style>





                share|improve this answer























                • ...then you have to do manually by showing a layer inside layout and changing status bar colour accordingly How? Isn't that the question? Your answer looks incomplete.
                  – azizbekian
                  Dec 10 '17 at 10:03










                • @azizbekian Check whether that dim is gone in your phone by using style specified in answer. I don't have that kind of phone to test with
                  – Sangeet Suresh
                  Dec 10 '17 at 10:42















                up vote
                0
                down vote













                BottomSheetDialogFragment extends DialogFragment. Inside BottomSheetDialog it's creating a Dialog inside onCreateDialog



                public class BottomSheetDialogFragment extends AppCompatDialogFragment {

                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                return new BottomSheetDialog(getContext(), getTheme());
                }

                }


                The dim layer is a property of dialog which is applying to whole window. Then only it will cover the status bar. If you need dim layer without bottom buttons, then you have to do manually by showing a layer inside layout and changing status bar colour accordingly.



                Apply theme for dialogfragment as given below



                class LogoutBottomSheetFragment : BottomSheetDialogFragment() {
                init {
                setStyle(DialogFragment.STYLE_NORMAL,R.style.dialog);
                }

                override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
                val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
                return view
                }


                }


                With styles as



                 <style name="dialog" parent="Base.Theme.AppCompat.Dialog">
                <item name="android:windowBackground">@android:color/transparent</item>
                <item name="android:backgroundDimEnabled">false</item>
                </style>





                share|improve this answer























                • ...then you have to do manually by showing a layer inside layout and changing status bar colour accordingly How? Isn't that the question? Your answer looks incomplete.
                  – azizbekian
                  Dec 10 '17 at 10:03










                • @azizbekian Check whether that dim is gone in your phone by using style specified in answer. I don't have that kind of phone to test with
                  – Sangeet Suresh
                  Dec 10 '17 at 10:42













                up vote
                0
                down vote










                up vote
                0
                down vote









                BottomSheetDialogFragment extends DialogFragment. Inside BottomSheetDialog it's creating a Dialog inside onCreateDialog



                public class BottomSheetDialogFragment extends AppCompatDialogFragment {

                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                return new BottomSheetDialog(getContext(), getTheme());
                }

                }


                The dim layer is a property of dialog which is applying to whole window. Then only it will cover the status bar. If you need dim layer without bottom buttons, then you have to do manually by showing a layer inside layout and changing status bar colour accordingly.



                Apply theme for dialogfragment as given below



                class LogoutBottomSheetFragment : BottomSheetDialogFragment() {
                init {
                setStyle(DialogFragment.STYLE_NORMAL,R.style.dialog);
                }

                override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
                val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
                return view
                }


                }


                With styles as



                 <style name="dialog" parent="Base.Theme.AppCompat.Dialog">
                <item name="android:windowBackground">@android:color/transparent</item>
                <item name="android:backgroundDimEnabled">false</item>
                </style>





                share|improve this answer














                BottomSheetDialogFragment extends DialogFragment. Inside BottomSheetDialog it's creating a Dialog inside onCreateDialog



                public class BottomSheetDialogFragment extends AppCompatDialogFragment {

                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                return new BottomSheetDialog(getContext(), getTheme());
                }

                }


                The dim layer is a property of dialog which is applying to whole window. Then only it will cover the status bar. If you need dim layer without bottom buttons, then you have to do manually by showing a layer inside layout and changing status bar colour accordingly.



                Apply theme for dialogfragment as given below



                class LogoutBottomSheetFragment : BottomSheetDialogFragment() {
                init {
                setStyle(DialogFragment.STYLE_NORMAL,R.style.dialog);
                }

                override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
                val view = inflater.inflate(R.layout.view_image_source_chooser, container, false)
                return view
                }


                }


                With styles as



                 <style name="dialog" parent="Base.Theme.AppCompat.Dialog">
                <item name="android:windowBackground">@android:color/transparent</item>
                <item name="android:backgroundDimEnabled">false</item>
                </style>






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 10 '17 at 10:42

























                answered Dec 10 '17 at 8:04









                Sangeet Suresh

                1,3211114




                1,3211114












                • ...then you have to do manually by showing a layer inside layout and changing status bar colour accordingly How? Isn't that the question? Your answer looks incomplete.
                  – azizbekian
                  Dec 10 '17 at 10:03










                • @azizbekian Check whether that dim is gone in your phone by using style specified in answer. I don't have that kind of phone to test with
                  – Sangeet Suresh
                  Dec 10 '17 at 10:42


















                • ...then you have to do manually by showing a layer inside layout and changing status bar colour accordingly How? Isn't that the question? Your answer looks incomplete.
                  – azizbekian
                  Dec 10 '17 at 10:03










                • @azizbekian Check whether that dim is gone in your phone by using style specified in answer. I don't have that kind of phone to test with
                  – Sangeet Suresh
                  Dec 10 '17 at 10:42
















                ...then you have to do manually by showing a layer inside layout and changing status bar colour accordingly How? Isn't that the question? Your answer looks incomplete.
                – azizbekian
                Dec 10 '17 at 10:03




                ...then you have to do manually by showing a layer inside layout and changing status bar colour accordingly How? Isn't that the question? Your answer looks incomplete.
                – azizbekian
                Dec 10 '17 at 10:03












                @azizbekian Check whether that dim is gone in your phone by using style specified in answer. I don't have that kind of phone to test with
                – Sangeet Suresh
                Dec 10 '17 at 10:42




                @azizbekian Check whether that dim is gone in your phone by using style specified in answer. I don't have that kind of phone to test with
                – Sangeet Suresh
                Dec 10 '17 at 10:42










                up vote
                0
                down vote













                In BottomSheetDialogFragment, the only thing that needs to be done is to set the container of the underlying CoordinatorLayout fitSystemWindows to false.



                override fun onActivityCreated(savedInstanceState: Bundle?) {
                super.onActivityCreated(savedInstanceState)
                (view!!.parent.parent.parent as View).fitsSystemWindows = false
                }




                • view is your layout


                • view.parent is a FrameLayout containing your view


                • view.parent.parent is the CoordinatorLayout


                • view.parent.parent.parent is the container for CoordinatorLayout which has its fitsSystemWindow set to true by default.


                This ensures that the whole BottomSheetDialogFragment is drawn underneath the navigation bar. Then you can set the fitsSystemWindows to your own containers accordingly.



                What you don't need from the other answers in particular is:




                • hacky findViewById with reference to system ids, which are subject to change,

                • reference to getWindow() or getDialog(),

                • no drawables to be set in the place of navigation bar.


                This solution works with BottomSheetDialogFragment created with onCreateView, I did not check onCreateDialog.






                share|improve this answer

























                  up vote
                  0
                  down vote













                  In BottomSheetDialogFragment, the only thing that needs to be done is to set the container of the underlying CoordinatorLayout fitSystemWindows to false.



                  override fun onActivityCreated(savedInstanceState: Bundle?) {
                  super.onActivityCreated(savedInstanceState)
                  (view!!.parent.parent.parent as View).fitsSystemWindows = false
                  }




                  • view is your layout


                  • view.parent is a FrameLayout containing your view


                  • view.parent.parent is the CoordinatorLayout


                  • view.parent.parent.parent is the container for CoordinatorLayout which has its fitsSystemWindow set to true by default.


                  This ensures that the whole BottomSheetDialogFragment is drawn underneath the navigation bar. Then you can set the fitsSystemWindows to your own containers accordingly.



                  What you don't need from the other answers in particular is:




                  • hacky findViewById with reference to system ids, which are subject to change,

                  • reference to getWindow() or getDialog(),

                  • no drawables to be set in the place of navigation bar.


                  This solution works with BottomSheetDialogFragment created with onCreateView, I did not check onCreateDialog.






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    In BottomSheetDialogFragment, the only thing that needs to be done is to set the container of the underlying CoordinatorLayout fitSystemWindows to false.



                    override fun onActivityCreated(savedInstanceState: Bundle?) {
                    super.onActivityCreated(savedInstanceState)
                    (view!!.parent.parent.parent as View).fitsSystemWindows = false
                    }




                    • view is your layout


                    • view.parent is a FrameLayout containing your view


                    • view.parent.parent is the CoordinatorLayout


                    • view.parent.parent.parent is the container for CoordinatorLayout which has its fitsSystemWindow set to true by default.


                    This ensures that the whole BottomSheetDialogFragment is drawn underneath the navigation bar. Then you can set the fitsSystemWindows to your own containers accordingly.



                    What you don't need from the other answers in particular is:




                    • hacky findViewById with reference to system ids, which are subject to change,

                    • reference to getWindow() or getDialog(),

                    • no drawables to be set in the place of navigation bar.


                    This solution works with BottomSheetDialogFragment created with onCreateView, I did not check onCreateDialog.






                    share|improve this answer












                    In BottomSheetDialogFragment, the only thing that needs to be done is to set the container of the underlying CoordinatorLayout fitSystemWindows to false.



                    override fun onActivityCreated(savedInstanceState: Bundle?) {
                    super.onActivityCreated(savedInstanceState)
                    (view!!.parent.parent.parent as View).fitsSystemWindows = false
                    }




                    • view is your layout


                    • view.parent is a FrameLayout containing your view


                    • view.parent.parent is the CoordinatorLayout


                    • view.parent.parent.parent is the container for CoordinatorLayout which has its fitsSystemWindow set to true by default.


                    This ensures that the whole BottomSheetDialogFragment is drawn underneath the navigation bar. Then you can set the fitsSystemWindows to your own containers accordingly.



                    What you don't need from the other answers in particular is:




                    • hacky findViewById with reference to system ids, which are subject to change,

                    • reference to getWindow() or getDialog(),

                    • no drawables to be set in the place of navigation bar.


                    This solution works with BottomSheetDialogFragment created with onCreateView, I did not check onCreateDialog.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 11 at 14:48









                    Michał K

                    6,43774279




                    6,43774279






















                        up vote
                        -1
                        down vote













                        Don't use BottomSheetDialogFragment.I would prefer use adding bottom sheet by wrapping the layout in the coordinator layout and attaching BottomSheetBehaiviour to that layout



                        You can follow this as an example






                        share|improve this answer





















                        • I would like to have the dim effect without writing this code myself. This will be my last resort if I will not find a fix for this issue
                          – oferiko
                          Dec 9 '17 at 17:55










                        • It is not possible because opening a dialog pauses the current activity so you won't be able have any interaction with the activity
                          – Farmaan Elahi
                          Dec 9 '17 at 17:58















                        up vote
                        -1
                        down vote













                        Don't use BottomSheetDialogFragment.I would prefer use adding bottom sheet by wrapping the layout in the coordinator layout and attaching BottomSheetBehaiviour to that layout



                        You can follow this as an example






                        share|improve this answer





















                        • I would like to have the dim effect without writing this code myself. This will be my last resort if I will not find a fix for this issue
                          – oferiko
                          Dec 9 '17 at 17:55










                        • It is not possible because opening a dialog pauses the current activity so you won't be able have any interaction with the activity
                          – Farmaan Elahi
                          Dec 9 '17 at 17:58













                        up vote
                        -1
                        down vote










                        up vote
                        -1
                        down vote









                        Don't use BottomSheetDialogFragment.I would prefer use adding bottom sheet by wrapping the layout in the coordinator layout and attaching BottomSheetBehaiviour to that layout



                        You can follow this as an example






                        share|improve this answer












                        Don't use BottomSheetDialogFragment.I would prefer use adding bottom sheet by wrapping the layout in the coordinator layout and attaching BottomSheetBehaiviour to that layout



                        You can follow this as an example







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Dec 9 '17 at 10:36









                        Farmaan Elahi

                        854914




                        854914












                        • I would like to have the dim effect without writing this code myself. This will be my last resort if I will not find a fix for this issue
                          – oferiko
                          Dec 9 '17 at 17:55










                        • It is not possible because opening a dialog pauses the current activity so you won't be able have any interaction with the activity
                          – Farmaan Elahi
                          Dec 9 '17 at 17:58


















                        • I would like to have the dim effect without writing this code myself. This will be my last resort if I will not find a fix for this issue
                          – oferiko
                          Dec 9 '17 at 17:55










                        • It is not possible because opening a dialog pauses the current activity so you won't be able have any interaction with the activity
                          – Farmaan Elahi
                          Dec 9 '17 at 17:58
















                        I would like to have the dim effect without writing this code myself. This will be my last resort if I will not find a fix for this issue
                        – oferiko
                        Dec 9 '17 at 17:55




                        I would like to have the dim effect without writing this code myself. This will be my last resort if I will not find a fix for this issue
                        – oferiko
                        Dec 9 '17 at 17:55












                        It is not possible because opening a dialog pauses the current activity so you won't be able have any interaction with the activity
                        – Farmaan Elahi
                        Dec 9 '17 at 17:58




                        It is not possible because opening a dialog pauses the current activity so you won't be able have any interaction with the activity
                        – Farmaan Elahi
                        Dec 9 '17 at 17:58










                        up vote
                        -1
                        down vote













                        I had the same problem. After looking into sources I found a workaround (a little bit hacky, but I found no alternatives).



                        public class YourDialog extends BottomSheetDialogFragment {

                        //your code

                        @NonNull
                        @Override
                        public Dialog onCreateDialog(Bundle savedInstanceState) {
                        return new FitSystemWindowsBottomSheetDialog(getContext());
                        }
                        }

                        public class FitSystemWindowsBottomSheetDialog extends BottomSheetDialog {

                        public FitSystemWindowsBottomSheetDialog(Context context) {
                        super(context);
                        }

                        @Override
                        protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        if (getWindow() != null && Build.VERSION.SDK_INT >= 21) {
                        findViewById(android.support.design.R.id.coordinator).setFitsSystemWindows(false);
                        findViewById(android.support.design.R.id.container).setFitsSystemWindows(false);
                        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
                        WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                        }
                        }
                        }


                        And, finally, don't forget to add android:fitsSystemWindows="true" at the root of your dialog layout.



                        Hope it helps.






                        share|improve this answer

























                          up vote
                          -1
                          down vote













                          I had the same problem. After looking into sources I found a workaround (a little bit hacky, but I found no alternatives).



                          public class YourDialog extends BottomSheetDialogFragment {

                          //your code

                          @NonNull
                          @Override
                          public Dialog onCreateDialog(Bundle savedInstanceState) {
                          return new FitSystemWindowsBottomSheetDialog(getContext());
                          }
                          }

                          public class FitSystemWindowsBottomSheetDialog extends BottomSheetDialog {

                          public FitSystemWindowsBottomSheetDialog(Context context) {
                          super(context);
                          }

                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          if (getWindow() != null && Build.VERSION.SDK_INT >= 21) {
                          findViewById(android.support.design.R.id.coordinator).setFitsSystemWindows(false);
                          findViewById(android.support.design.R.id.container).setFitsSystemWindows(false);
                          getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
                          WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                          getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                          }
                          }
                          }


                          And, finally, don't forget to add android:fitsSystemWindows="true" at the root of your dialog layout.



                          Hope it helps.






                          share|improve this answer























                            up vote
                            -1
                            down vote










                            up vote
                            -1
                            down vote









                            I had the same problem. After looking into sources I found a workaround (a little bit hacky, but I found no alternatives).



                            public class YourDialog extends BottomSheetDialogFragment {

                            //your code

                            @NonNull
                            @Override
                            public Dialog onCreateDialog(Bundle savedInstanceState) {
                            return new FitSystemWindowsBottomSheetDialog(getContext());
                            }
                            }

                            public class FitSystemWindowsBottomSheetDialog extends BottomSheetDialog {

                            public FitSystemWindowsBottomSheetDialog(Context context) {
                            super(context);
                            }

                            @Override
                            protected void onCreate(Bundle savedInstanceState) {
                            super.onCreate(savedInstanceState);
                            if (getWindow() != null && Build.VERSION.SDK_INT >= 21) {
                            findViewById(android.support.design.R.id.coordinator).setFitsSystemWindows(false);
                            findViewById(android.support.design.R.id.container).setFitsSystemWindows(false);
                            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
                            WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                            }
                            }
                            }


                            And, finally, don't forget to add android:fitsSystemWindows="true" at the root of your dialog layout.



                            Hope it helps.






                            share|improve this answer












                            I had the same problem. After looking into sources I found a workaround (a little bit hacky, but I found no alternatives).



                            public class YourDialog extends BottomSheetDialogFragment {

                            //your code

                            @NonNull
                            @Override
                            public Dialog onCreateDialog(Bundle savedInstanceState) {
                            return new FitSystemWindowsBottomSheetDialog(getContext());
                            }
                            }

                            public class FitSystemWindowsBottomSheetDialog extends BottomSheetDialog {

                            public FitSystemWindowsBottomSheetDialog(Context context) {
                            super(context);
                            }

                            @Override
                            protected void onCreate(Bundle savedInstanceState) {
                            super.onCreate(savedInstanceState);
                            if (getWindow() != null && Build.VERSION.SDK_INT >= 21) {
                            findViewById(android.support.design.R.id.coordinator).setFitsSystemWindows(false);
                            findViewById(android.support.design.R.id.container).setFitsSystemWindows(false);
                            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
                            WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                            }
                            }
                            }


                            And, finally, don't forget to add android:fitsSystemWindows="true" at the root of your dialog layout.



                            Hope it helps.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 9 at 14:26









                            j2esu

                            841921




                            841921






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47553936%2fprevent-bottomsheetdialogfragment-covering-navigation-bar%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Florida Star v. B. J. F.

                                Danny Elfman

                                Lugert, Oklahoma