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

Min SDK   8
Latest Commit   2015-08-06 12:15:11
License   MIT

Github   https://github.com/nispok/snackbar

         

标签

使用APP客户端扫描二维码运行Demo


         

类似的还有....
MaterialEditText EditText in Material Design
material-ripple Android L Ripple effect wrapper for Views
Widgets-Skeleton A skeleton of google's appcompat android navigation drawer with material design.
README

README.md

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