Convert Figma logo to code with AI

MrEngineer13 logoSnackBar

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

1,222
174
1,222
13

Top Related Projects

A curated list of awesome Android UI/UX libraries

5,515

An Android Alerting Library

6,569

The usual Toast, but with steroids 💪

[Moved to MavenCentral] An Android library that takes the standard toast to the next level with many styling options. Works on all Android versions.

A library that extends the Android toast framework.

Quick Overview

SnackBar is an Android library that provides a customizable and easy-to-use implementation of the Material Design Snackbar component. It offers a simple way to display brief messages at the bottom of the screen with optional actions, allowing for a seamless user experience in Android applications.

Pros

  • Easy integration with minimal setup required
  • Highly customizable appearance and behavior
  • Supports both top and bottom positioning of the Snackbar
  • Offers queue management for multiple Snackbar messages

Cons

  • Limited to Android platform only
  • May require additional configuration for complex use cases
  • Potential conflicts with other libraries that modify the view hierarchy
  • Lacks some advanced features found in newer Material Design components

Code Examples

  1. Basic usage:
Snackbar.with(context)
    .text("Hello, Snackbar!")
    .show(activity)
  1. Customizing appearance:
Snackbar.with(context)
    .text("Custom Snackbar")
    .textColor(Color.WHITE)
    .color(Color.BLUE)
    .duration(Snackbar.SnackbarDuration.LENGTH_LONG)
    .show(activity)
  1. Adding an action:
Snackbar.with(context)
    .text("Message sent")
    .actionLabel("Undo")
    .actionColor(Color.YELLOW)
    .actionListener { 
        // Handle undo action
    }
    .show(activity)
  1. Displaying at the top of the screen:
Snackbar.with(context)
    .text("Top Snackbar")
    .position(Snackbar.SnackbarPosition.TOP)
    .show(activity)

Getting Started

  1. Add the dependency to your build.gradle file:
dependencies {
    implementation 'com.github.mrengineer13:snackbar:1.2.0'
}
  1. Use the Snackbar in your activity or fragment:
import com.github.mrengineer13.snackbar.SnackBar

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Snackbar.with(this)
            .text("Welcome to SnackBar!")
            .show(this)
    }
}

This will display a simple Snackbar message at the bottom of your activity. You can further customize the Snackbar by chaining additional methods as shown in the code examples above.

Competitor Comparisons

A curated list of awesome Android UI/UX libraries

Pros of awesome-android-ui

  • Comprehensive collection of UI libraries and components
  • Regularly updated with new and trending UI resources
  • Categorized for easy navigation and discovery

Cons of awesome-android-ui

  • Not a standalone library, requires additional implementation
  • May overwhelm developers with too many options
  • Lacks direct code examples for each listed resource

Code Comparison

SnackBar provides a simple implementation for creating and showing snackbars:

Snackbar.with(getApplicationContext())
        .text("Hello World")
        .show(this);

awesome-android-ui doesn't provide direct code examples, but it links to various UI libraries. For instance, a Material Design library it references might be used like this:

MaterialButton button = new MaterialButton(context);
button.setText("Click me");
layout.addView(button);

Summary

SnackBar is a focused library for creating snackbar notifications, while awesome-android-ui is a curated list of various Android UI libraries and resources. SnackBar offers a straightforward implementation for a specific UI element, whereas awesome-android-ui provides a wide range of options for different UI components and design patterns. Developers looking for a quick snackbar solution might prefer SnackBar, while those seeking inspiration or exploring various UI options would find awesome-android-ui more beneficial.

5,515

An Android Alerting Library

Pros of Alerter

  • More customizable appearance with options for icon, title, and text
  • Supports swipe-to-dismiss functionality
  • Offers built-in sound and vibration options

Cons of Alerter

  • Larger library size compared to SnackBar
  • May require more setup and configuration
  • Limited to top-of-screen alerts, less flexible positioning

Code Comparison

SnackBar:

Snackbar.make(view, "Message", Snackbar.LENGTH_LONG)
    .setAction("Action") { /* action code */ }
    .show()

Alerter:

Alerter.create(this)
    .setTitle("Title")
    .setText("Message")
    .setIcon(R.drawable.ic_alert)
    .setDuration(3000)
    .show()

Both libraries offer simple ways to display messages, but Alerter provides more built-in customization options in its basic implementation. SnackBar focuses on simplicity and follows Material Design guidelines more closely, while Alerter offers a wider range of visual customization out of the box. The choice between the two depends on the specific needs of the project, with SnackBar being more suitable for simple, Material Design-compliant notifications, and Alerter being better for highly customized, attention-grabbing alerts.

6,569

The usual Toast, but with steroids 💪

Pros of Toasty

  • More customization options for toast appearance and animations
  • Supports custom fonts and icons
  • Smaller library size, potentially reducing app bloat

Cons of Toasty

  • Limited to toast-style notifications only
  • Less flexibility in terms of action buttons and interaction

Code Comparison

Toasty:

Toasty.success(context, "Success!", Toast.LENGTH_SHORT, true).show()

SnackBar:

Snackbar.make(view, "Message", Snackbar.LENGTH_LONG)
        .setAction("Action", null)
        .show();

Summary

Toasty focuses on enhancing the standard Android toast notifications with more customization options, while SnackBar provides a broader range of notification types, including interactive elements. Toasty is more lightweight and specialized, whereas SnackBar offers greater flexibility for complex user interactions. The choice between the two depends on the specific needs of your application and the type of notifications you want to implement.

[Moved to MavenCentral] An Android library that takes the standard toast to the next level with many styling options. Works on all Android versions.

Pros of StyleableToast

  • More customization options for toast appearance
  • Supports icons and custom fonts
  • Easier to create consistent toast styles across the app

Cons of StyleableToast

  • Limited to toast messages only, not suitable for action-based notifications
  • May require more setup time for custom styles

Code Comparison

StyleableToast:

StyleableToast.makeText(context, "Hello World!", R.style.myToast).show()

SnackBar:

Snackbar.make(view, "Hello World!", Snackbar.LENGTH_LONG)
        .setAction("Action", null)
        .show();

Summary

StyleableToast offers more visual customization for toast messages, making it ideal for apps that require unique and consistent toast styles. However, SnackBar provides action-based notifications, which can be more useful for interactive user feedback. StyleableToast is simpler to use for basic toast messages, while SnackBar offers more functionality at the cost of slightly more complex implementation.

A library that extends the Android toast framework.

Pros of SuperToasts

  • More customization options for toast appearance and behavior
  • Supports additional toast types like progress and button toasts
  • Includes a built-in queue system for managing multiple toasts

Cons of SuperToasts

  • Less actively maintained (last update was several years ago)
  • More complex API, which may increase the learning curve
  • Larger library size due to additional features

Code Comparison

SuperToasts:

SuperToast.create(this, "Hello, SuperToast!", 
    SuperToast.Duration.MEDIUM, 
    Style.getStyle(Style.RED, SuperToast.Animations.FLYIN))
    .show();

SnackBar:

Snackbar.make(view, "Hello, SnackBar!", Snackbar.LENGTH_LONG)
    .setAction("Action", null)
    .show();

SuperToasts offers more customization options in a single method call, while SnackBar provides a simpler, more streamlined API. SuperToasts allows for easy styling and animation selection, whereas SnackBar focuses on a clean, material design-compliant implementation with fewer options but easier integration with modern Android design principles.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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.

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