Git Product home page Git Product logo

snackbar-1's Introduction

SnackBar

Android Arsenal API

#Designed after the docs at Google Material Design

screenshot

#Features

  • Customization including message, action message, action color, message color, background color, action click handle, animation duration, and animation interpolator
  • Tablet support
  • Swipe to dismiss
  • Callbacks for the different SnackBar states (started, actionClicked, finished)
  • One Message at a time
  • XML Style support

#Using SnackBar

Using SnackBar is simple, just one line of code is needed!

SnackBar.show(getActivity(), R.string.hello_world);

Or if you want to set an action

SnackBar.show(getActivity(), R.string.hello_world, R.string.undo, onClickListener);

#Customization

SnackBars can be customized by creating a SnackBarItem with the Builder factory

SnackBarItem sbi = new SnackBarItem.Builder(getActivity())
.setMessageResource(R.string.message)
.setActionMessageResource(R.string.action)
.setObject(myObject)
.setActionClickListener(myClickListener)
.setActionMessageColorResource(R.color.my_red)
.setSnackBarMessageColorResource(R.color.my_yellow)
.setSnackBarBackgroundColorResource(R.color.my_green)
.setInterpolatorResource(android.R.interpolator.accelerate_decelerate)
.setDuration(5000)
.setSnackBarListener(myListener)
.show();

###SnackBars can also be styled via the application theme The following attributes can be used for styling a SnackBar

   <attr name="snack_bar_background_color" format="color" />
   <attr name="snack_bar_text_color" format="color" />
   <attr name="snack_bar_text_action_color" format="color" />
   <attr name="snack_bar_duration" format="integer" />
   <attr name="snack_bar_interpolator" format="reference" />
   ...
   ...
   ...
   ...
   <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@color/background_material_light</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="snack_bar_text_color">@color/my_color</item>
        <item name="snack_bar_duration">5000</item>
    </style>

Receive callbacks from SnackBars with an Object

// Called when the SnackBar begins to animate
@Override
publc void onSnackBarStarted(Object object){
}

// Called when the action button is pressed
@Override
public void onSnackBarAction(Object object){
}

// Called when the SnackBar finishes with its animation
// Will be called if the action button is pressed
@Override
public void onSnackBarFinished(Object object){
}

Canceling SnackBars

When your activity goes into a Paused or Destroyed state, remove the SnackBars from the queue

SnackBar.cancelSnackBars(getActivity());

#Migrating from 1.X Version 2.X has brought many changes.

First, support for pre HoneyComb has been dropped. Version 1.1 is still available, but no more work will be devoted to anything pre SDK 11.

Second, the snack_bar_text_action_color_pressed attribute has been removed. The action on the SnackBar is now a native button, so it will used the built in selector for the pressed states.

Lastly, the SnackBarItem.Builder class now takes an activity in the constructor to allow the passing of resource ids into the builder methods.

#Including in your project To include SnackBar in your project, add the following to your build.gradle file.

repositories {
   maven { url 'https://dl.bintray.com/kennyc1012/maven' }
}


dependencies {
    compile 'com.kennyc:snackbar:2.0.2'
}

If you need support for pre HoneyComb, you can still use the 1.1 release, but all support has been dropped for it

repositories {
   maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}


dependencies {
    // For api8+ you also need to comple NineOldAndroids
    compile 'com.github.kennyc1012:snackbar:1.1-SNAPSHOT:api8Release@aar'
    compile 'com.nineoldandroids:library:2.4.0'
}

#Contribution Pull requests are welcomed and encouraged. If you experience any bugs, please file an issue

snackbar-1's People

Contributors

johnjohndoe avatar kennyc1012 avatar

Watchers

 avatar  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.