2

I am trying to focus designing like this:

enter image description here

for this, I have added inside onCreate

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

Now Layout got expanded but it somehow hides my snackbar behind the nav bar which is not the desired result as it should be above.Here's my screenshot:

enter image description here

I might have approached wrong way and it would be very helpful if you correct me.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Avinash
  • 145
  • 9
  • View rootView = activity.getWindow().getDecorView().findViewById(android.R.id.content); Snackbar snackbar = Snackbar.make(rootView, message, 2000); @Droidwala, View sView = snackbar.getView(); TextView textView = (TextView) sView.findViewById(android.support.design.R.id.snackbar_text); – Avinash Nov 16 '17 at 12:32

4 Answers4

1

From here: add margins for your snackbar, 48dp should be enough.

public static void displaySnackBarWithBottomMargin(Snackbar snackbar, int sideMargin, int marginBottom) {
    final View snackBarView = snackbar.getView();
    final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) snackBarView.getLayoutParams();

    params.setMargins(params.leftMargin + sideMargin,
                params.topMargin,
                params.rightMargin + sideMargin,
                params.bottomMargin + marginBottom);

    snackBarView.setLayoutParams(params);
    snackbar.show();
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
svkaka
  • 3,942
  • 2
  • 31
  • 55
0

Do not use "rootView" instance for creating Snackbar, instead use getView() like below

Snackbar snackbar = Snackbar.make(getView(), "Your Message", Snackbar.LENGTH_LONG);
snackbar.show();
Roshan
  • 381
  • 3
  • 8
0

I fixed the problem by using this technique:

1- add a View to my layout

2- set Snackbar setAnchorView

In your XML

<View
        android:id="@+id/snackBarAnchor"
        android:layout_width="0.1dp"
        android:layout_height="0.1dp"
        android:layout_alignParentBottom="true" />

in your code

          snackbar.setAnchorView(R.id.snackBarAnchor)
Momen Zaqout
  • 1,508
  • 1
  • 16
  • 17
-2

There is no need for guesswork with LayoutParams (which can leave your Snackbar in weird positions on different screens)

Instead just ensure the root of your layout is a CoordinatorLayout. Make sure the coordinator is also the View given to the snackbar (don't use v.getRootView() as this can be another view)

You may need to give an id to the coordinator and pass that as the view:

new Snackbar.make(findViewById(R.id.coordinator), ...).show()
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124