Coder Social home page Coder Social logo

snackbar's Introduction

SnackBar; toast-like alert pattern for Android inspired by the Google Material Design Spec

SnackBar on Android Arsenal

Mr.Waffle

Deprecated

This library is deprecated in favor of the new Design Support Library which includes a Snackbar. It is due to this development that this library is no longer activly being developed.

Features

  • Set message text and optionally duration
  • Shows only one message at a time
  • Can have action item (e.g. undo, refresh, etc.)
  • Set text color of action items
  • Swipe down to dismiss all notifications as per documentation
  • Backwards compatible to 2.3.x

New Features since 1.0.0

  • Set custom background color
  • Set custom height
  • Set custom typeface

SnackBar Screenshot via Google

SnackBar on Google Play

Usage

  1. Add SnackBar to your project ###Maven Just add the following to your build.gradle.

    dependencies { compile 'com.github.mrengineer13:snackbar:1.2.0' }

  2. Show a message

Build SnackBar in Activity

new SnackBar.Builder(this)
    .withOnClickListener(this)
    .withMessage("This library is awesome!") // OR
    .withMessageId(messageId)
    .withTypeFace(myAwesomeTypeFace)

    .withActionMessage("Action") // OR
    .withActionMessageId(actionMsgId)

    .withTextColorId(textColorId)
    .withBackGroundColorId(bgColorId)
    .withVisibilityChangeListener(this)
    .withStyle(style)
    .withDuration(duration)
    .show();

Build SnackBar in Fragment

new SnackBar.Builder(getActivity().getApplicationContext(), root)
    .withOnClickListener(this)
    .withMessage("This library is awesome!") // OR
    .withMessageId(messageId)
    .withTypeFace(myAwesomeTypeFace)

    .withActionMessage("Action") // OR
    .withActionMessageId(actionMsgId)

    .withTextColorId(textColorId)
    .withBackGroundColorId(bgColorId)
    .withVisibilityChangeListener(this)
    .withStyle(style)
    .withDuration(duration)
    .show();

Using this library?

If you're using this library in one of your projects just send me a tweet and I'll add your project to the list.

Icon Application
Plume
Score It
Lotería Navidad 2014
Journal
My Garage
QuoteMe

Contribution

Pull requests are welcome!

Feel free to contribute to SnackBar.

Just create your branch then submit pull request on the dev branch.

If you have a bug to report a feature to request or have other questions, file an issue. I'll try to answer as soon as I can.

snackbar's People

Contributors

aaronrietschlin avatar battleshippark avatar he-lu avatar mrengineer13 avatar ntsh avatar rashiq avatar stephanebg avatar tankery avatar tasomaniac avatar tommienu avatar tomrozb avatar wching avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snackbar's Issues

Follow Google Material Guidelines

As per Material guidelines the snackbar should:

  • Slide bottom-up while fading in at the same time and hide with the opposite animation (Watch the video on the guidelines site).
  • The undo button should highlight its text when pressed. Normally the highlight colour should be the one chosen as primary.
  • Animation time should be of no longer than 300 ms for fast and fluid appearance.

Optional:

  • In case of the existence of a FAB button located at the bottom of the screen then the Snackbar should accommodate space for itself pushing the FAB button up.

java.lang.NoClassDefFoundError: com.github.mrengineer13.snackbar.SnackBar

Hello,

Wherever I want to use the lib as you use it in the sample app:

            SnackBar snackBar = new SnackBar(activity);
            snackBar.show("Some text", SnackBar.MED_SNACK);

There is a crash when calling the constructor. It's kind of weird so I tried to call it on different activities getting the same result.

Any help will be appreciated.

Thanks in advance

Display error with Google Maps

I want to show a status message when there is no network connection. For some reason the SnackBar looks like this on a Google Map:

SnackBar Error

The event is triggered in onCameraChange() which happens when I swipe the map. Maybe there there is an issue when multiple events occur?

Is it possible to show the toast with duration infinity

Hi,

This library looks cool. And i want to use this snackbar as toast in my app and i need to show a toast for retry action when no network is found and it shouldn't auto hide. It should be shown to the user till the user clicks retry button. Is it possible to do this with this library?

Thanks.

Add custom typeface

Hi,
Please add a method for changing default typeface:
setTypeface(Typeface typeface);

Transparent nav bar

When using KK+ transparent styles, the SnackBar appears behind the nav bar.

Either bottom padding or a bottom margin would be nice to make the resting position above the nav bar.

Great library!

background of toast dosent appear

I am Trying to use your library in my fragment.but i am getting This Type Of Output
screenshot_2014-08-30-16-17-45

What i want is same output as your sample app

here's my code:

SnackBar mSnackBar;

mSnackBar = new SnackBar((MainActivity) getActivity());
mSnackBar.show("This is my Toast", "UNDO");
mSnackBar.setOnClickListener(new SnackBar.OnMessageClickListener() {
@OverRide
public void onMessageClick(Parcelable token) {
Toast.makeText(((MainActivity) getActivity()), "adaa",
Toast.LENGTH_LONG).show();
}
});

Fragment usage...

When using the fragment usage, what is the behavior? IS the behavior dependent on whether on a tablet (float offset from lower left corner) or small device (against bottom, pushing up the current bottom view).

If this isn't the behavior, it would be nice if it was, as it would do all the work of bumping up various obscured views...

Message is centered

I'm using it like this:

new SnackBar.Builder(this)
    .withMessageId(messageId)
    .show();

In my case message is displayed centered in the snackbar box. Isn't it a bug?

Spellchecker active on text & button text

a red line appears under text that is not recognized by the systems spellchecker due to a another default language than the application. Could this be turned off in the standard layout?

Doesn't show in Lollipop

Hello !
I can't get the snackbar to show in lollipop. It works fine in Jelly bean.
Anybody know what's the issue ?

Regards !

Callback Once Snackbar Disappears

I'm not sure if this exists currently or not but a good feature would be a callback so when the dialog disappears you can run a function. Prefect for any undo button, simply don't do anything until the callback is called.

Hide Snackbar

I want the snack bar to be hidden on touch on the snack bar or the snackaction. Any idea hoe to do that.

DrawerLayout behind SnackBar?

I'm using a layout with a DrawerLayout and when the drawer becomes active, it renders behind a SnackBar I have set in the current layout with an infinite duration. Although you can dismiss the SnackBar, is there anyway I can have the SnackBar render behind the DrawerLayout/make the DrawerLayout render above it?

Snackbar not show when rotating screen

After i rotate the screen the snackbar wond't show any more.
Ik trayed it with the onSaveInstanceState but it does't work.

How can i solve dis? am i doing somting wrong?

Testing a Snackbar in a Fragment with Robolectric fails

When testing a Snackbar in a Fragment with Robolectric the test fails due to an UnsupportedOperationException. Any idea how to solve this?

java.lang.UnsupportedOperationException: ugh, this doesn't work still?
    at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:290)
    at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:273)
    at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:85)
    at android.content.res.AssetManager.getResourceValue(AssetManager.java)
    at android.content.res.Resources.getValue(Resources.java:1114)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2304)
    at android.content.res.Resources.getLayout(Resources.java:934)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at com.github.mrengineer13.snackbar.SnackBar.<init>(SnackBar.java:96)
    at com.myapp.MyFragment.showFailed(MyFragment.java:273)
    at com.myapp.MyFragmentRobolectricTest.showFailed_success(MyFragmentRobolectricTest.java:58)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:250)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Reset duration

Hi.

I'm in the case that i need to rest the duration, because i show one SnackBar and before it dismiss i will show again if not exist, or let SnackBar to stay in the screen the duration time agian.

Can it be implemented?

SnackBar,resetProgress()

?

Is ok if i try to do a PR?

On Tablet devices

Just wondering how the Snackbar should be displayed on larger devices per the guidelines? On my Nexus 7 it floats a little to the right and probably 10dp from the bottom.

Long text in tablet

When I set long text with tablet, the layout has maxHeight and maxWidth. So it cuts the text when it is too long.

Style?

Hi!
I use this:

    new SnackBar.Builder(this)
            .withMessageId(R.string.title_on)
            .withStyle(SnackBar.Style.INFO)
            .withDuration(SnackBar.SHORT_SNACK)
            .show();

Unfortunately, no style is not changed. As displayed by default, and displays in all directions of style.

Button text is underlined

I tried to fix it but I didnt find why it's happening. On the second displayed snackbar, the button text is underlined.
I use your library in my application. You can find the source code here to reproduce the issue.
https://github.com/StephaneBg/ScoreItProject

Other problem, long click on the button shows "Paste" system tooltip.
screenshot_2014-09-20-12-37-31
screenshot_2014-09-18-18-11-36

onShow onHide listener

Hi.

I need to modify the UI when the snackbar is shown.

Default UI
UI with Snackbar

But now the SnackBar is shown above the Button
Button behind

How can I achieve this with this library?

Text Selector color for SnackButton

Hi, I noticed that the default text selector for the SnackButton seems a bit odd.

  <item android:state_pressed="true"
        android:color="#22000000"/> <!-- pressed -->
  <item android:state_focused="true"
        android:color="#22000000"/> <!-- focused -->
  <item android:color="#ffffff"/>  <!--default --> 

screen shot - - at

I feel that state_pressed and state_focused should be only slightly darker. It's just what I think. I am not sure whether you put it purposely or not.

IDE files

You should not commit IDE files. They are local files.
.idea and *.iml should be added to gitignore.

Null Views and NPE when dealing with fragments

The validity of a view reference should be checked before attempting to show the SnackBar. When using SnackBar and suppling the view in the builder for the fragments, there's a slight chance that when the SnackBar is building the view is no longer available, hence causing a NullPointerException.

An easy way to produce this is showing SnackBar in asynchronous callbacks in the fragments. Simply start an asynchronous job and navigate away from the fragment.

Infinite SnackBar

Is there any option to never hide the SnackBar? Only if the action button is pressed?

Commit gradle.properties file

Please commit gradle.properties file. Project won't compile without it.

Error:(20, 0) Could not find property 'VERSION_NAME' on root project 'SnackBar'.

NullPointerException when instantiated using `SnackBar(Context, View)`

Example code:

SnackBar snackBar = new SnackBar(getContext(), SomeCustomCompoundView.this);

Stack trace:

   Process: com.example.app, PID: 12578
    java.lang.NullPointerException
            at com.github.mrengineer13.snackbar.SnackBar.init(SnackBar.java:108)
            at com.github.mrengineer13.snackbar.SnackBar.<init>(SnackBar.java:102)
            at ...

I suspect this might be due to an invalid usage of SnackBar, but I wanted to get some input since it's not clear. I'm calling this within a compound view which is part of a ListView. With the given method signature, I would expect SnackBar to be able to find the appropriate "snack container" in the view hierarchy. From looking at the constructors in SnackBar at

it seems SnackBar only inflates its layout container into the Activity's layout when the SnackBar(Activity) constructor is called, and not when the SnackBar(Context, View) constructor is called.

Not shown from Preference Fragment

If I'm using a standard activity that hosts a PreferenceFragment, the snackbar is not shown.

  1. Creating the Snackbar in the activity, not the fragment.
  2. Showing the Snackbar from the activity, after fragment issues the command.

Thoughts?

Snackbar not showing when activity is resumed

suppose i'm on Activity A then I show snackbar message it shows without any errors. then I call Activity B and come back to Activity A then the snack bar is not showing.

A => B => A ----> call show() not displaying anything...

SnackBar blocks input

With the last release, when a SnackBar is displayed, it is not possible to touch the rest of the screen.

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.