Snacky is a small library to help you adding a Snackbar to your android project.

Overview

API

Donate

Snacky

Snacky is a small library to help you adding a Snackbar to your layout with ease. It was created because of my own needs and is inspired by Toasty. Snacky uses an easy builder pattern to build a Snackbar and gives you some template designs like ERROR, WARNING, INFO and SUCCESS as well as some customization options. See code samples below

‼️ As of version 1.1.4 Snacky is is only compatible with androidX and not longer with support library apps! ‼️

Screenshots

Default

Success

Info

Warning

Error

Custom

Usage

Using Snacky is really simple.

Initialisation

Start with Snacky.builder() to get a Builder.

It is necessary to set an activity or View for the snackbar.

.setView(View view) will use the view for the snackbar to show, or you choose

.setActivity(Activity activity) which will automatically find the root view of the activity

Customization

most of them are self-explaining, all colors are not Resource Ids, but parsed colors, so use ContextCompat.getColor() if you want to use Resource-colors)

.setBackgroundColor() Color

.setText() Charset or IntRes for text

.setTextColor() Color or ColorStateList

.setTextSize() size in SP or with ComplexUnit

.setTextTypeface() Typeface

.setTextTypefaceStyle() NORMAL, BOLD, ITALIC, BOLD_ITALIC from Typeface

.setMaxLines() max lines of Snackbar, off by default

.centerText() centers the text

.setActionText()

.setActionTextColor() Color or ColorStateList

.setActionTextSize()

.setActionTextTypeface()

.setActionTextTypefaceStyle() like .setTextTypefaceStyle()

.setActionClickListener(View.OnClickListener)

.setDuration(Snacky.DURATION) SHORT, LONG, INDEFINITE

.setIcon() Drawable to be shown, in my opinion ist best to use small drawables with 24dp size

Building

.build() gives you the Snackbar, but you can also use some predefined templates:

.success()

.error()

.info()

.warning()

All give you a snackbar object, but some set predefined values if you didn't customize them before.

Using the snackbar

After that you can handle the snackbar as you know it:

.addCallback(SnackBar.Callback) adds a callback to the snackbar

.show() shows the snackbar

Example

See ExampleActivity.java for a list of examples as shown in Screenshots.

There you can also the see the right use of CoordinatorLayout and FloatingActionButton. For Snacky Builder just use the view from OnClickListener in FAB to animate it on click.

Installation

Snacky is published via Jitpack. Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Add this to your module's build.gradle file (make sure the version matches the JitPack badge above):

dependencies {
    ...
    implementation 'com.github.matecode:Snacky:1.1.5'
    implementation 'com.google.android.material:material:1.0.0'
}

Licence

Copyright 2018 Mate Siede

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Failed to resolve Snacky

    Failed to resolve Snacky

    com.github.matecode:Snacky:1.0.2

    Are you sure Snacky still on Maven, i checked it on the central repository. It not found. https://search.maven.org/#search%7Cga%7C1%7Csnacky

    That same in dependencies of android studio .

    question 
    opened by congdanh1608 2
  • setActionTextColor not work properly

    setActionTextColor not work properly

    Hi, first of all, thanks for this awesome library. I had some problem with this peace of code.

    val snacky = Snacky.builder() .setView(root) .setText(msg) .setDuration(time) .setBackgroundColor(Color.WHITE) .setTextColor(R.color.material_color_blue_grey_500) .setTextTypeface(ResourcesCompat.getFont(this, R.font.montserrat_regular)) .setActionTextTypeface(ResourcesCompat.getFont(this, R.font.montserrat_bold)) .setActionTextColor(R.color.colorAccent) .build()

    Result -> the action text color had the same color of text message

    Thanks

    opened by cepero91 1
  • Snacky has extra top padding

    Snacky has extra top padding

    When I show a Snacky, it has a extra top padding in it like this: screenshot_1500862473

    the layout is

        <?xml version="1.0" encoding="utf-8"?>
        <android.support.design.widget.CoordinatorLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white">
    
            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/AppTheme.AppBarOverlay">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/toolbarColor"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
            </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:paddingTop="8dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
        </android.support.design.widget.CoordinatorLayout>
    

    Showing code is

            Snacky.builder()
                    .setView(recyclerView)
                    .warning()
                    .setText("账号已删除")
                    .setAction("恢复", { actionCallback() })
                    .setDuration(Snacky.LENGTH_LONG)
                    .show()
    

    Activity's theme is "AppTheme.NoActionBar"

            <style name="BaseAppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
                <item name="windowActionBar">false</item>
                <item name="windowNoTitle">true</item>
            </style>
    
            <style name="AppTheme" parent="BaseAppTheme">
                <!-- Customize your theme here. -->
                <item name="colorPrimary">@color/colorPrimary</item>
                <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
                <item name="colorAccent">@color/colorAccent</item>
    
                <item name="colorControlActivated">@color/colorControlActivated</item>
                <item name="colorControlHighlight">@color/colorControlHighlight</item>
                <item name="colorControlNormal">@color/colorControlNormal</item>
    
                <item name="topSnackbarBackground">@color/colorPrimaryDark</item>
                <item name="topSnackbarForeground">@color/colorAccent</item>
    
                <item name="fabColor">@color/colorPrimary</item>
                <item name="fabIconColor">@android:color/white</item>
    
                <item name="bottomNavColor">@color/colorPrimary</item>
                <item name="bottomNormalColor">@color/colorBottomNormal</item>
                <item name="bottomActiveColor">@android:color/white</item>
                <item name="bottomRippleColor">@color/colorBottomRipple</item>
    
                <item name="toolbarColor">@color/colorPrimary</item>
                <item name="toolbarNormalColor">@android:color/white</item>
    
                <item name="itemBgColor">@android:color/white</item>
                <item name="itemQuoteBgColor">@color/colorQuoteBackground</item>
                <item name="itemTextColor">@android:color/primary_text_light</item>
                <item name="itemTextSecondaryColor">@color/colorTextSecondary</item>
                <item name="itemNormalColor">@color/colorPrimary</item>
                <item name="itemActiveColor">@color/colorPrimaryDark</item>
                <item name="itemRippleColor">@color/colorPrimaryRipple</item>
                <item name="itemIconColor">@color/selector_icon_button_color</item>
    
                <item name="iconInactiveColor">@color/colorInactiveColor</item>
                <item name="iconActiveColor">@color/colorActiveColor</item>
    
                <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
    
    
                <item name="windowActionBar">false</item>
                <item name="windowNoTitle">true</item>
                <item name="android:navigationBarColor" tools:targetApi="21">@color/colorPrimaryDark</item>
                <!--<item name="android:windowTranslucentStatus">true</item>-->
            </style>
    
            <style name="AppTheme.NoActionBar" parent="AppTheme">
                <item name="android:windowActionBar">false</item>
                <item name="android:windowNoTitle">true</item>
                <item name="android:windowTranslucentStatus">true</item>
                <item name="android:windowTranslucentNavigation">false</item>
            </style>
    

    This issues show now only on API 19, but it show on and API >=19 but it has been fixed by some way I don't know.

    opened by xanahopper 1
  • setActivity() misspelled

    setActivity() misspelled

    Instead of setActivity() it's setActivty()

                   Snacky.builder()
                          .setBackgroundColor(R.color.white)
                          .setActivty(Activity.this)
                          ...
    
    bug 
    opened by personaljesusua 1
  • Action text size

    Action text size

    Hi,

    I changed the text size of snacky and works great, but action text size wont change.

    snacky

    As you can see in attached screenshot, action button on the right side, is smaller than message text.

    enhancement 
    opened by arashmidos 1
  • Respect bottom navigation bars

    Respect bottom navigation bars

    According to the Material Design Guidelines (https://material.io/guidelines/components/snackbars-toasts.html#), a snackbar should not block any input. Currently, Snacky snackbars overlay over a android.support.design.widget.BottomNavigationView for example and therefore are blocking input.

    Any chance that this gets changed in a coming version of Snacky?

    //edit: Just realized that Snacky does this very well if one uses .setView(View view) to set the correct bottom navigation bar view.

    opened by neoscaler 0
  • Add background drawable support

    Add background drawable support

    Sometime, we need to custom the Snackbar's background. So I added the setter for background by drawable resource

    Snacky.builder()
        .setBackgroundResource(R.drawable.shape_background_white_round_corner)
        ...
        .build()
        .show();
    
    opened by akexorcist 0
  • setDuration

    setDuration

    setDuration() needs a positive and greater than Zero number, however, all durations are negative or zero.

    Android studio error: code = setDuration(Snacky.LENGTH_LONG) error =

    Must be one of: BaseTransientBottomBar.LENGTH_INDEFINITE, BaseTransientBottomBar.LENGTH_SHORT, BaseTransientBottomBar.LENGTH_LONG or value must be ≥ 1 (was -2)

    opened by Mojtaba-Shafaei 1
  • Proguard is weak

    Proguard is weak

    Hi,

    I see in consumer-proguard-rules.pro these lines.:

    -keep public class * { public protected *; }

    if we include this library in a multi module project, Proguard keep ALL classes, even those are not in this library. (Indeed Android Studio Plugin append all Proguard files)

    feedback wanted 
    opened by Wahyd 4
Owner
Mate
Mate
The usual Snackbar with more 🍫 and colours :tada:

ChocoBar The usual Snackbar with more ?? and colours ?? . Inspired by Light. GIF AndroidPub Post You can read the AndroidPub post about this library,

Pradyuman Dixit 124 Dec 20, 2022
a Custom Snackbar Library for Jetpack Compose 🚀🎨

?? Snackie is a custom snackbar library for jetpack compose built without using the built in snackbar component ?? Implementation repositories { ma

MathRoda 10 Dec 24, 2022
Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app

DroidMVP About DroidMVP is a small Android library to help you incorporate the MVP pattern along with Passive View and Presentation Model (yes, those

Andrzej Chmielewski 225 Nov 29, 2022
Android Snackbar from the Top (similar to Crouton)

Top Snackbar Sadly, I don't have time to maintain this. If you'd like to be a maintainer, drop me a message in an issue Show a Snackbar from the top.

Dan Ξ 1.1k Dec 17, 2022
The usual Snackbar with more 🍫 and colours :tada:

ChocoBar The usual Snackbar with more ?? and colours ?? . Inspired by Light. GIF AndroidPub Post You can read the AndroidPub post about this library,

Pradyuman Dixit 124 Dec 20, 2022
A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

WhatTodo Life can feel overwhelming. But it doesn’t have to. A Simple To-do app design in flutter to keep track of your task on daily basis. You can a

Burhanuddin Rashid 1k Jan 1, 2023
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 27, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 21, 2022
Chandrasekar Kuppusamy 799 Nov 14, 2022
A small tool to help you generate android projects that have a base code.

Volt Project A small tool to help you generate android projects that have a base code. Usage Change project in base directory. python volt-gen.py <pac

Victor Varenik 3 Feb 2, 2022
Small library that allows the application to display a small troubleshooting guide in case of repeated app startup crashes.

AppSalvager What is it? AppSalvager allows you to combat the issue of repeating crashes on app startup. Failed data migration, SDKs not handling their

Alexander Leontev 29 Aug 31, 2022
👋 A common toolkit (utils) ⚒️ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! 🍭

Toolkit [ ?? Work in progress ⛏ ?? ??️ ?? ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

凛 35 Jul 23, 2022
A very simple Android app which shows you random memes with the help of meme-api which you can share with your friends!

Meme Share A very simple Android app which shows you random memes with the help of meme-api which you can share with your friends! Tech stack 100% wri

Stɑrry Shivɑm 8 Aug 10, 2022
A small library to help with Realm.IO integration in Android apps

Android Realm Asset Helper A small library of methods to help with Realm.IO integration in Android apps Copies a realm database from a the assets fold

Quality Mobile Puzzle Apps 29 Dec 28, 2021
Android library for adding price range with chart like in airbnb with flexible customization. Made by Stfalcon

Stfalcon-PriceRangeBar Demo Application Who we are Need iOS and Android apps, MVP development or prototyping? Contact us via [email protected]. We dev

Stfalcon LLC 223 Nov 25, 2022
This plugin help you to set material design icon to your project.

Android Material Design Icon Generator Plugin This plugin help you to set material design icons to your Android project. Installation Manually Downloa

Yusuke Konishi 2.4k Dec 30, 2022
MVVM Redux is a lightweight lib to help you apply the redux concepts in your project based in MVVM.

MVVM Redux is a lightweight lib to help you apply the redux concepts in your project based in MVVM.

Gabriel Brasileiro 36 Oct 16, 2022
A funny project to help you test your BNF syntax

Readme The idea of this project is to implement a BNF expression compiler. We could use BNF to design some syntax like Arithmetic expression. <factor>

Jack Chen 4 Dec 21, 2022