Coder Social home page Coder Social logo

snackbar's Introduction

Snackbar

Build Status Android Arsenal

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

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.3.0'

Usage


Using the Snackbar class is easy, this is how you would display it on a HelloWorldActivity:
```java Snackbar.with(getApplicationContext()) // context .text("Single-line snackbar") // text to display .show(this); // activity where it is displayed ``` If you want an action button to be displayed, just assign a label and an ActionClickListener:
```java Snackbar.with(getApplicationContext()) // context .text("Item deleted") // text to display .actionLabel("Undo") // action button label .actionListener(new ActionClickListener() { @Override public void onActionClicked() { Log.d(TAG, "Undoing something"); } }) // action button's ActionClickListener .show(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:
```java Snackbar.with(getApplicationContext()) // context .text("This will do something when dismissed") // text to display .eventListener(new EventListener() { @Override public void onShow(int height) { myFloatingActionButton.moveUp(height); } @Override public void onDismiss(int height) { myFloatingActionButton.moveDown(height); } }) // Snackbar's DismissListener .show(this); // activity where it is displayed ``` There are two Snackbar types: single-line (default) and multi-line (2 lines max). You can also set the duration of the Snackbar similar to a Toast. Animation disabling is also possible.
```java 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 .show(this); // where it is displayed ``` You can also change the Snackbar's colors.
```java Snackbar.with(getApplicationContext()) // context .text("Different colors this time") // text to be displayed .textColor(Color.GREEN) // change the text color .color(Color.BLUE) // change the background color .actionLabel("Action") // action button label .actionColor(Color.RED) // action button label color .actionListener(new ActionClickListener() { @Override public void onActionClicked() { Log.d(TAG, "Doing something"); } }) // action button's ActionClickListener .show(this); // activity where it is displayed ``` Finally, you can attach the Snackbar to a AbsListView (ListView, GridView) or a RecyclerView.
```java 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) // make it shorter .animation(false) // don't animate it .attachToAbsListView(listView) // Attach to ListView - attachToRecyclerView() is for RecyclerViews .show(this); // where it is displayed ``` It uses [Roman Nurik's SwipeToDismiss sample code](https://github.com/romannurik/android-swipetodismiss) to implement the swipe-to-dismiss functionality. This is enabled by default. You can disable this if you don't want this functionality:

```java Snackbar.with(SnackbarSampleActivity.this) // context .text("Can't swipe this") // text to be displayed .swipeToDismiss(false) // disable swipe-to-dismiss functionality .show(this); // activity where it is displayed ``` If you would like to add features to it or report any bugs, refer to the [issues](https://github.com/nispok/snackbar/issues) section.

Who's using Snackbar?

If you are using this library and would like to be mentioned here, open a PR or tell us via email.

Examples

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

Contributors

License

MIT

snackbar's People

Contributors

ashughes avatar davidjrichardson avatar i906 avatar lewisjdeane avatar mdxdave avatar wmora avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.