Search code examples
androidmaterial-designandroid-stylesandroid-snackbar

Android Material Snackbar Old Style


Since Android Studio 4.1 the Snackbar is in a new style (from the built-in Material library):

enter image description here

But I still prefer the old style:

enter image description here

How to achieve that? I've searched around the internet but still can't find the answer.


Solution

  • Snackbars can span the entire width of the screen only when a UI does not use persistent navigation components like app bars or bottom navigation bars. Snackbars that span the entire width of a UI can push only FABs up when they appear.

    Since I don't have your code you can try setting the style of Snackbar by adding this line in your AppTheme in styles.xml or themes.xml:

    <item name="snackbarStyle">@style/Widget.MaterialComponents.Snackbar.FullWidth</item>
    

    Or programmatically you can try this:

    // Create the Snackbar
    Snackbar snackbar = Snackbar.make(containerLayout, "", Snackbar.LENGTH_LONG);
    // Get the Snackbar's layout view
    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
    //If the view is not covering the whole snackbar layout, add this line
    layout.setPadding(0,0,0,0);
    // Show the Snackbar
    snackbar.show();