[] Android Library that implements Snackbars from Google's Material Design documentation.

Overview

DEPRECATED

This lib is deprecated in favor of Google's Design Support Library which includes a Snackbar and is no longer being developed.

Thanks for all your support!

Snackbar

Build Status Maven Central Android Arsenal Android Weekly

Library that implements Snackbars from Google's Material Design documentation. Works on API levels >= 8

Get it on Google Play

Example App

Example App

Example App

Example App

Example App

Installation

You can import the library from source as a module or grab via Gradle:

compile 'com.nispok:snackbar:2.11.+'

Usage

Using the Snackbar class is easy, this is how you would display it on an Activity:

Snackbar.with(getApplicationContext()) // context
    .text("Single-line snackbar") // text to display
    .show(this); // activity where it is displayed

However, I recommend you use the SnackbarManager to handle the Snackbars queue:

// Dismisses the Snackbar being shown, if any, and displays the new one
SnackbarManager.show(
    Snackbar.with(myActivity)
    .text("Single-line snackbar"));

If you are using getApplicationContext() as the Context to create the Snackbar then you must specify the target Activity when calling the SnackbarManager:

// Dismisses the Snackbar being shown, if any, and displays the new one
SnackbarManager.show(
    Snackbar.with(getApplicationContext())
    .text("Single-line snackbar"), myActivity);

You can place the Snackbar at the bottom of a particular hierarchy of views. The sample app makes use of this; check out SnackbarImmersiveModeSampleActivity:

SnackbarManager.show(Snackbar snackbar, ViewGroup parent) { }
SnackbarManager.show(Snackbar snackbar, ViewGroup parent, boolean usePhoneLayout) { }

If you want an action button to be displayed, just assign a label and an ActionClickListener:

SnackbarManager.show(
    Snackbar.with(getApplicationContext()) // context
        .text("Item deleted") // text to display
        .actionLabel("Undo") // action button label
        .actionListener(new ActionClickListener() {
            @Override
            public void onActionClicked(Snackbar snackbar) {
                Log.d(TAG, "Undoing something");
            }
        }) // action button's ActionClickListener
     , this); // activity where it is displayed

If you need to know when the Snackbar is shown or dismissed, assign a EventListener to it. This is useful if you need to move other objects while the Snackbar is displayed. For instance, you can move a Floating Action Button up while the Snackbar is on screen. Note that if you only need to override a subset of the interface methods you can extend from EventListenerAdapter:

SnackbarManager.show(
    Snackbar.with(getApplicationContext()) // context
        .text("This will do something when dismissed") // text to display
        .eventListener(new EventListener() {
            @Override
            public void onShow(Snackbar snackbar) {
                myFloatingActionButton.moveUp(snackbar.getHeight());
            }
            @Override
            public void onShowByReplace(Snackbar snackbar) {
                Log.i(TAG, String.format("Snackbar will show by replace. Width: %d Height: %d Offset: %d",
                                        snackbar.getWidth(), snackbar.getHeight(),
                                        snackbar.getOffset()));
            }
            @Override
            public void onShown(Snackbar snackbar) {
                Log.i(TAG, String.format("Snackbar shown. Width: %d Height: %d Offset: %d",
                        snackbar.getWidth(), snackbar.getHeight(),
                        snackbar.getOffset()));
            }
            @Override
            public void onDismiss(Snackbar snackbar) {
                myFloatingActionButton.moveDown(snackbar.getHeight());
            }
            @Override
            public void onDismissByReplace(Snackbar snackbar) {
                Log.i(TAG, String.format(
                                "Snackbar will dismiss by replace. Width: %d Height: %d Offset: %d",
                                snackbar.getWidth(), snackbar.getHeight(),
                                snackbar.getOffset()));
            }
            @Override
            public void onDismissed(Snackbar snackbar) {
                Log.i(TAG, String.format("Snackbar dismissed. Width: %d Height: %d Offset: %d",
                                    snackbar.getWidth(), snackbar.getHeight(),
                                    snackbar.getOffset()));
            }
        }) // Snackbar's EventListener
    , this); // activity where it is displayed

There are two Snackbar types: single-line (default) and multi-line (2 lines max. Note this only applies for phones; tablets are always single-line). You can also set the duration of the Snackbar similar to a Toast.

The lengths of a Snackbar duration are:

  • LENGTH_SHORT: 2s
  • LENGTH_LONG: 3.5s (default)
  • LENGTH_INDEFINTE: Indefinite; ideal for persistent errors

You could also set a custom duration.

Animation disabling is also possible.

SnackbarManager.show(
    Snackbar.with(getApplicationContext()) // context
        .type(Snackbar.SnackbarType.MULTI_LINE) // Set is as a multi-line snackbar
        .text("This is a multi-line snackbar. Keep in mind that snackbars are " +
            "meant for VERY short messages") // text to be displayed
        .duration(Snackbar.SnackbarDuration.LENGTH_SHORT) // make it shorter
        .animation(false) // don't animate it
    , this); // where it is displayed

You can also change the Snackbar's colors and fonts.

SnackbarManager.show(
    Snackbar.with(getApplicationContext()) // context
        .text("Different colors this time") // text to be displayed
        .textColor(Color.GREEN) // change the text color
        .textTypeface(myTypeface) // change the text font
        .color(Color.BLUE) // change the background color
        .actionLabel("Action") // action button label
        .actionColor(Color.RED) // action button label color
        .actionLabelTypeface(myTypeface) // change the action button font
        .actionListener(new ActionClickListener() {
            @Override
            public void onActionClicked(Snackbar snackbar) {
                Log.d(TAG, "Doing something");
            }
         }) // action button's ActionClickListener
    , this); // activity where it is displayed

Finally, you can attach the Snackbar to a AbsListView (ListView, GridView) or a RecyclerView.

SnackbarManager.show(
    Snackbar.with(getApplicationContext()) // context
        .type(Snackbar.SnackbarType.MULTI_LINE) // Set is as a multi-line snackbar
        .text(R.string.message) // text to be displayed
        .duration(Snackbar.SnackbarDuration.LENGTH_LONG)
        .animation(false) // don't animate it
        .attachToAbsListView(listView) // Attach to ListView - attachToRecyclerView() is for RecyclerViews
        , this); // where it is displayed

It uses Roman Nurik's SwipeToDismiss sample code to implement the swipe-to-dismiss functionality. This is enabled by default. You can disable this if you don't want this functionality:

NOTE: This has no effect on apps running on APIs < 11; swiping will always be disabled in those cases

SnackbarManager.show(
    Snackbar.with(SnackbarSampleActivity.this) // context
        .text("Can't swipe this") // text to be displayed
        .swipeToDismiss(false) // disable swipe-to-dismiss functionality
    , this); // activity where it is displayed

Examples

There's a sample app included in the project. SnackbarSampleActivity is where you want to start.

Apps Using Snackbar

Contributing

If you would like to add features or report any bugs, open a PR or refer to the issues section.

Contributors

Thanks to all contributors!

License

MIT

ChangeLog

Go to the releases section for a brief description of each release.

Comments
  • Modified callbacks so listeners receive full information of the process of showing / dimissing snackbars

    Modified callbacks so listeners receive full information of the process of showing / dimissing snackbars

    onShow() and onDismiss() are now both referred to when the action is about to occur and there are new callbacks for when the action is completed called onShown() and onDismissed() for now (it can be changed to whatever seems best and consistent)

    opened by jrgonzalezg 21
  • FC

    FC

    Snackbar crashes, because textview in snackbar.xml and color in colors.xml had named by the same id snackbar_text. It throw java.lang.NoSuchFieldError: No static field snackbar_text of type I in class Lcom/nispok/snackbar/R$id; or its superclasses (declaration of 'com.nispok.snackbar.R$id' at com.nispok.snackbar.Snackbar.init(Snackbar.java:226)

    opened by desugar-64 17
  • Snackbar shown behind navigation bar

    Snackbar shown behind navigation bar

    Hello,

    I'm using your lib and it works pretty well on all devices I've tested it, but just discovered that on version 4.4.2 (At least on LG G3) when using translucentNavigation bar the snackbar is shown behind the navigation bar. Neither clipToPadding nor fitsSystemWindows solve the problem.

    Screenshot : https://s3.amazonaws.com/pushbullet-uploads/udqLC-dxEqYkHwmGpyu7qBM3kgN24ksiAwphAE/Screenshot_2014-12-12-20-08-34.png

    Thanks in advanced

    bug 
    opened by CarlosMChica 14
  • Action button text should be Roboto Medium

    Action button text should be Roboto Medium

    According to the Material Design spec, the action button text should be Roboto Medium, while the message text should be Roboto Regular. I was looking into how to do this, but there doesn't seem to be an easy solution.

    One option would be to bundle the Roboto Medium (and Roboto Regular?) fonts with the library and set the TextViews accordingly.

    Another option is to add a dependency for a library like https://github.com/johnkil/Android-RobotoTextView or https://github.com/chrisjenx/Calligraphy

    I also just came across https://bitbucket.org/josephearl/foundry, which might be helpful.

    Any other ideas/thoughts?

    opened by ashughes 13
  • IllegalStateException in AccessibilityManager.

    IllegalStateException in AccessibilityManager.

    This is the stack trace.

    1639-1639/com.nispok.samples.snackbar E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.nispok.samples.snackbar, PID: 1639 java.lang.IllegalStateException: Accessibility off. Did you forget to check that? at android.view.accessibility.AccessibilityManager.sendAccessibilityEvent(AccessibilityManager.java:309) at android.view.ViewRootImpl.requestSendAccessibilityEvent(ViewRootImpl.java:6158) at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:737) at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:737) at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:737) at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:737) at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:737) at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:737) at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5294) at android.view.View.sendAccessibilityEventUnchecked(View.java:5275) at com.nispok.snackbar.Snackbar.focusForAccessibility(Snackbar.java:838) at com.nispok.snackbar.Snackbar.access$1700(Snackbar.java:45) at com.nispok.snackbar.Snackbar$7.onAnimationEnd(Snackbar.java:809) at android.view.animation.Animation$3.run(Animation.java:374) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

    opened by rohans310 12
  • Tag (or somethin)?

    Tag (or somethin)?

    Hey! First of all - thanks for a superb library. Secondly - maybe it would be nice to have a String tag (or something) to identify a Snackbar and update already showing, or simply remove the previous Snack?

    opened by noties 10
  • Snackbar showing at incorrect vertical offset

    Snackbar showing at incorrect vertical offset

    I was testing my app on an 4.0.3 emulated device and realized that the snackbar was not actually showing at the bottom of the screen but at an higher offset.

    The emulated device I was using does not have navigation button but it does the same for devices with navigation buttons on 4.0.3. To help pin point the problem, this activity is using the new appcompat v7 Toolbar where the activity is set with no action bar and the new toolbar is somewhat part of the content for pre-android 5 devices.

    Here's a screenshot of the problem: device-2014-12-24-231733

    opened by stevegaron 8
  • Set Right to left direction

    Set Right to left direction

    it's great to use SnackBar in non Lollipop android version, and have lot of option for developer, i want to use snakeBar with RightToLeft Direction like this :

    righttolefrsnakes

    try this code to set RTL direction, but it's not work !?

    Snackbar snackbar=Snackbar.with(getApplicationContext())
          .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
          .text("متاسفانه خطایی در ثبت مکان رخ داده است. ")
          .actionLabel("بستن");
    snackbar.setLayoutDirection(SnackbarLayout.LAYOUT_DIRECTION_RTL);
    snackbar.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
    SnackbarManager.show(snackbar,GetActivity());
    

    is there any solution to set Direction Like this ?

    enhancement 
    opened by atahani 7
  • Ability to disable swipe gesture.

    Ability to disable swipe gesture.

    I believe it is not defined in the Material Design Guideline. And the new inbox application does not do it. You cannot swipe there. I think it shouldn't be enabled by default.

    opened by tasomaniac 7
  • Snackbar leaks activity

    Snackbar leaks activity

    Version 2.10.+ (2.10.8) Snackbar leaks activity if activity is closed while snackbar is visible.

    GC ROOT static com.nispok.snackbar.SnackbarManager.currentSnackbar * references com.nispok.snackbar.Snackbar.mTargetActivity * leaks com.example.MainActivity instance

    Snackbar is displayed in activity: SnackbarManager.show(Snackbar.with(this).type(SnackbarType.MULTI_LINE).text("text")); //dismissing onPause doesn't solve issue onPause(){ SnackbarManager.dismiss(); }

    opened by martinvandzura 6
  • Snackbar appears behind dialogs

    Snackbar appears behind dialogs

    If I show a snackbar in response to a button clicked in a dialog, it shows behind the dialog's dim layer. It should appear on top of everything when summoned IMO

    bug 
    opened by ZacSweers 6
Releases(2.11.0)
  • 2.11.0(Aug 6, 2015)

  • 2.10.10(May 31, 2015)

  • v2.10.9(May 25, 2015)

  • v2.10.7(Apr 18, 2015)

  • v2.10.6(Mar 24, 2015)

  • v2.10.5(Mar 17, 2015)

  • v2.10.4(Mar 17, 2015)

  • v2.10.3(Mar 15, 2015)

  • v2.10.2(Mar 7, 2015)

  • v2.10.1(Mar 1, 2015)

  • v2.10.0(Feb 28, 2015)

  • v2.9.1(Feb 18, 2015)

  • v2.9.0(Feb 11, 2015)

    • You can attach a Snackbar to a non-root Activity view. This closes #62 and provides a workaround for #76 and #27. The following methods are now included as part of the SnackbarManager: SnackbarManager.show(Snackbar snackbar, ViewGroup parent) and SnackbarManager.show(Snackbar snackbar, ViewGroup parent, boolean usePhoneLayout)
    • Navigation bar handling has been improved. Fixing #45. See #80 for more detail and the latest demo for more detail
    • An EventListenerAdapter is provided to avoid boilerplate code if you only need to override a subset of EventListener. See #81
    Source code(tar.gz)
    Source code(zip)
  • v2.8.0(Feb 8, 2015)

    • A Snackbar's action button can only be tapped once by default. If you really need the action button to be tapped multiple times (can't think of an scenario where you would want this) you have to set explicitly set this behavior
    Snackbar.with(context).allowMultipleActionClicks(true);
    
    • A method isActionClicked() is now provided to let you know if the action button was tapped. This is useful if you want to know during the Snackbar dimissal if it's being dismissed because the action was tapped or just ran out of time. See #73
    • The EventListener has been extended with a couple of calls: onShowByReplace and onDismissByReplace. This is useful if you need to NOT move a Floating Action Button down and up while the Snackbar is just being replaced, but still wanted to move up and down on regular show/dismiss callbacks. See #79
    • Support for translucent navigation bar. For translucent navigation bars, their height size is added in the Snackbar's bottom padding. The sample app illustrates this
    • A bug has been fixed when the configured color for either the background, text, or action text was white. Prior to this version, the color code #ffffffff was always ignored. See #67 and this SO question
    Source code(tar.gz)
    Source code(zip)
  • v2.7.5(Jan 24, 2015)

    • You can set a custom typeface for a Snackbar text and action text. See #71
    • You can now get the current Snackbar from the SnackbarManager. See #66
    • RecyclerView is marked as a provided dependency. See #71
    Source code(tar.gz)
    Source code(zip)
  • v2.7.4(Jan 11, 2015)

  • v2.7.3(Dec 28, 2014)

  • v2.7.2(Dec 24, 2014)

  • v2.7.1(Dec 23, 2014)

  • v2.7.0(Dec 21, 2014)

    SnackbarDuration.INDEFINITE was added as a SnackbarDuration which would keep it on screen indefinitely, needing to be dismissed by swipe or action. See #46

    Source code(tar.gz)
    Source code(zip)
  • v2.6.1(Dec 20, 2014)

    • Added "sb__" prefix to all resources that were missing it
    • Fixed NPE when attempting to recycle the velocity tracker used when swiping (#49)
    Source code(tar.gz)
    Source code(zip)
  • v2.6.0(Dec 18, 2014)

  • v2.5.5(Dec 18, 2014)

  • v2.5.2(Dec 8, 2014)

    • Fixed issue where onDismiss() did not get called if Snackbar is swiped #38
    • Removed deprecated animation duration getter. Use animation resource getters instead #39
    Source code(tar.gz)
    Source code(zip)
  • v2.5.1(Dec 8, 2014)

    Included static getters for animation resources. In that way, clients can apply the same animation or if the exact same animation does not work depending on the use case, they can query the specific fields they need.

    The getters are Snackbar.getInAnimationResource() and Snackbar.getOutAnimationResource(). The getter getAnimationDuration() has now been deprecated. You should query that directly from the resource

    Source code(tar.gz)
    Source code(zip)
  • v2.5.0(Dec 7, 2014)

    • EventListener now has two new events: onShown() and onDismissed(). This way you have control over the whole animation cycle. Note that now each event will receive the Snackbar instance instead of just the height, so you will have to modify your code if updating from a previous version
    • Fixed the min/max width and offset for the tablet layout
    • Removed bold style from action button
    Source code(tar.gz)
    Source code(zip)
  • v2.4.0(Dec 4, 2014)

    The minSDK version of the library has been lowered to 8.

    Note that any apps running on APIs < 11 will not have the swipe-to-dismiss functionality. Enabling it explicitly won't have any effect.

    Source code(tar.gz)
    Source code(zip)
  • v2.3.1(Dec 3, 2014)

  • v2.3.0(Nov 25, 2014)

    • Reintroduced tablet support, initially introduced with #7. When Inbox was released, the Snackbars used in there did not follow the specs from the guidelines for tablets, so the initial implementation was dropped
    • Single-line snackbars are now 48dp tall as specified in the guidelines. The padding was left a bit different, however: 14dp at the top and 14dp at the bottom vs 16dp/12dp in the specs
    Source code(tar.gz)
    Source code(zip)
  • v2.2.2(Nov 24, 2014)

Owner
null
A library to bring fully animated Material Design components to pre-Lolipop Android.

Material MaterialLibrary is an Open Source Android library that back-port Material Design components to pre-Lolipop Android. MaterialLibrary's origina

Rey Pham 6k Dec 21, 2022
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

MaterialDrawer ... the flexible, easy to use, all in one drawer library for your Android project. What's included ?? • Setup ??️ • Migration Guide ??

Mike Penz 11.6k Dec 27, 2022
A library support form with material design, construct same with Android UI Framework

SwingUI A slight Java Swing library support form with material design, construct same with Android UI Framework writen in Kotlin Supported: 1. Screen:

Cuong V. Nguyen 3 Jul 20, 2021
A Material Design ViewPager easy to use library

MaterialViewPager Material Design ViewPager easy to use library Sample And have a look on a sample Youtube Video : Youtube Link Download In your modul

Florent CHAMPIGNY 8.2k Jan 1, 2023
Material Shadows for android : A library for supporting convex material shadows

MaterialShadows A library for seamlessly integrating Material shadows. The library takes existing material shadows to next level by adding the followi

Harjot Singh Oberai 2.2k Dec 19, 2022
Floating Action Button for Android based on Material Design specification

FloatingActionButton Yet another library for drawing Material Design promoted actions. Features Support for normal 56dp and mini 40dp buttons. Customi

Zendesk 6.4k Dec 26, 2022
Implementation of Ripple effect from Material Design for Android API 9+

RippleEffect ExpandableLayout provides an easy way to create a view called header with an expandable view. Both view are external layout to allow a ma

Robin Chutaux 4.9k Dec 30, 2022
Material Design implementation for Android 4.0+. Shadows, ripples, vectors, fonts, animations, widgets, rounded corners and more.

Carbon Material Design implementation for Android 4.0 and newer. This is not the exact copy of the Lollipop's API and features. It's a custom implemen

null 3k Jan 9, 2023
Android drawer icon with material design animation

LDrawer Android drawer icon with material design animation Note Basically same as appcompat_v7 version 21, you can use appcompat_v7 compile 'com.andro

Hasan Keklik 1.4k Dec 25, 2022
Android Sample Project with Material Design and Toolbar.

AndroidMaterialDesignToolbar -- PROJECT IS NOT SUPPORTED Android Sample Project with Material Design and Toolbar. Project use Appcompat library for ma

kemal selim tekinarslan 713 Nov 11, 2022
Android drawer icon with material design animation

LDrawer Android drawer icon with material design animation Note Basically same as appcompat_v7 version 21, you can use appcompat_v7 compile 'com.andro

Hasan Keklik 1.4k Dec 25, 2022
Floating Action Button for Android based on Material Design specification

FloatingActionButton Yet another library for drawing Material Design promoted actions. Features Support for normal 56dp and mini 40dp buttons. Customi

Zendesk 6.4k Jan 3, 2023
Android Material Design Components

Android-Material-Design-Components Material design is a comprehensive guide for visual, motion, and interaction design across platforms and devices. G

Velmurugan Murugesan 3 Jun 10, 2022
Modular and customizable Material Design UI components for Android

Material Components for Android Material Components for Android (MDC-Android) help developers execute Material Design. Developed by a core team of eng

Material Components 14.4k Dec 31, 2022
Easy creation and management of toggle buttons on Android from the Material Design spec.

ToggleButtonLayout Easy creation and management of toggle buttons from the Material Design spec. Read more about ToggleButtonLayout in our blog post.

Savvy 229 Jan 9, 2023
A gradle plugin that generates Material Design 3 theme for Android projects.

Same as Google's Material Theme Builder, but as a gradle plugin.

Rikka apps 41 Dec 6, 2022
Material Design icons by Google

Material design icons Material design icons is the official icon set from Google. The icons are designed under the material design guidelines. 4.0.0 U

Google 47.1k Jan 9, 2023
EditText in Material Design

MaterialEditText NOTE: 2.0 is NOT BACKWARDS COMPATIBLE! See more on wiki or 中文看这里 AppCompat v21 makes it easy to use Material Design EditText in our a

Kai Zhu 6.1k Dec 30, 2022
Material Design ProgressBar with consistent appearance

MaterialProgressBar Material Design ProgressBar with consistent appearance on Android 4.0+. Why MaterialProgressBar? Consistent appearance on Android

Hai Zhang 2.2k Dec 21, 2022