How to fix the height and position of the snack?

In the Android 24.1.1 support library, Snackbar worked fine:

before

Then, starting with the Android 24.2.0 support library , Snackbar began to behave like this:

after

In the revision history of the library, there is the following statement:

Behavioral changes: Snackbar now draws behind the navigation bar if the status bar is transparent.

But the fact is that my application runs in full screen mode and has neither a navigation bar nor a status bar. How can i fix this?

+6
source share
6 answers

fooobar.com/questions/1664677/...

 params.setMargins(params.leftMargin,
            params.topMargin,
            params.rightMargin,
            params.bottomMargin + ScreenUtils.getNavigationBarHeight(activity));

 params.setMargins(params.leftMargin,
            params.topMargin,
            params.rightMargin,
            params.bottomMargin - ScreenUtils.getNavigationBarHeight(activity));
+4

, Snackbar.

. , : Android

, Snackbar:

final Snackbar snackbar = Snackbar.make(findViewById(R.id.fullscreen_content),
                message, Snackbar.LENGTH_LONG);

View snackbarView = snackbar.getView();

// Adjust Snackbar height for fullscreen immersive mode
int navbarHeight = getNavigationBarSize(this).y;

CoordinatorLayout.LayoutParams parentParams = (CoordinatorLayout.LayoutParams) snackbarView.getLayoutParams();
    parentParams.setMargins(0, 0, 0, 0 - navbarHeight);
    snackbarView.setLayoutParams(parentParams);

snackbar.show();

, LayoutParams Layout. CoordinatorLayout , Snackbar.make() ( R.id.fullscreen_content - CoordinatorLayout). CoordinatorLayout , Snackbars , .

+8

, Snackbar . , , - SnackbarLayout ( Snackbar), , Snackbar , .

: https://github.com/material-components/material-components-android/blob/cd59e98f7e2185ddb075ff0fc91f29765d562968/lib/java/com/google/android/material/snackbar/BaseTransientjottom

, , . , OnApplyWindowInsetsListener ( Snackbar ):

ViewCompat.setOnApplyWindowInsetsListener(snackbar.view) { v, insets ->
    v.setPadding(v.paddingLeft, v.paddingTop, v.paddingRight, v.paddingTop)
    insets
}

, Snackbar , , :

ViewCompat.setOnApplyWindowInsetsListener(view) { v, insets ->
    v.setPadding(v.paddingLeft, v.paddingTop, v.paddingRight, v.paddingTop)

    val params = v.layoutParams as ViewGroup.MarginLayoutParams
    params.updateMargins(
        params.leftMargin,
        params.topMargin,
        params.rightMargin,
        params.bottomMargin + insets.systemWindowInsetBottom
    )
    v.layoutParams = params

    insets
}

- Material 1.1.0 ( , ), , , .

+2

,

FrameLayout.LayoutParams params =(FrameLayout.LayoutParams)view.getLayoutParams();
    params.gravity = Gravity.BOTTOM;
0

If all you care about is height, not position, then get ready for your mind to be blown up !: D

Set the contents of the diner:

Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            'Your SnackBar message',
          ),
          SizedBox(
            height: 70, // Your desired height
          )
        ],
      ))
0
source

Another way would be

Snackbar snackbar = Snackbar.make(view, ...);
View snackBarView = snackbar.getView();

ViewCompat.setFitsSystemWindows(snackBarView, false);
ViewCompat.setOnApplyWindowInsetsListener(snackBarView, null);

This will disable the extra bottom padding in dive mode.

0
source

Source: https://habr.com/ru/post/1664676/


All Articles