An easy to use and customisable wrapper of the native Android Snackbar which stays visible across multiple activities.

Related tags

App LGSnackbar
Overview

logo

travis_CI platform license API

An easy to use wrapper of the native Android Snackbar which stays visible across multiple activities. It provides different themes to start with, and allows you to easily manage common scenarios like success, warning, error, info.

Preview

Demo video:

logo

Try it on Appetize:

appetize

Install

In your root/build.gradle:

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

In your app/build.gradle

dependencies {
  compile 'com.github.loregr:lgsnackbar:1.0.2'
}

Preparing

Setup with a default theme

Define your default theme using LGSnackbarManager.prepare(...), in your Application class in the #onCreate() method.

@Override
public void onCreate() {
    super.onCreate();
    LGSnackbarManager.prepare(getApplicationContext(),
                LGSnackBarThemeManager.LGSnackbarThemeName.SHINE);
                //....
}

You can check the available themes here.

Note: You can simply call LGSnackbarManager.prepare(getApplicationContext()), in this case SHINE theme will be automatically applied.

Setup with a custom theme

Create your own LGSnackbarTheme by passing 4 LGSnackBarStyle instances (one for each scenario of the theme) and the minHeight and the duration values that you want to apply to the Snackbar.

@Override
public void onCreate() {
    super.onCreate();
    LGSnackbarManager.prepare(getApplicationContext(),
                    customTheme());
                //....
}

//...

LGSnackBarTheme customTheme() {
    LGSnackBarStyle successStyle = new LGSnackBarStyle(successCustomColor,
            Color.WHITE,
            actionSuccessCustomColor,
            R.drawable.ic_done_white);

    LGSnackBarStyle warningStyle = new LGSnackBarStyle(warningCustomColor,
            Color.WHITE,
            actionWarningCustomColor,
            R.drawable.ic_warning_white);

    LGSnackBarStyle errorStyle = new LGSnackBarStyle(errorCustomColor,
            Color.WHITE,
            actionErrorCustomColor,
            R.drawable.ic_error_outline_white);

    LGSnackBarStyle infoStyle = new LGSnackBarStyle(infoCustomColor,
            Color.WHITE,
            actionInfoCustomColor,
           R.drawable.ic_info_outline_white);

    return new LGSnackBarTheme(successStyle, warningStyle, errorStyle, infoStyle, 60, Snackbar.LENGTH_LONG);
}

Usage

After preparing is done, in order to show a snackbar you can simply call:

LGSnackbarManager.show(SUCCESS, "Everything is looking good! Awesome!");

Woooo, done! :-)

Callbacks and actions

You can add a callback and/or an action to your snackbar by calling:

Callback:

LGSnackbarManager.show(SUCCESS, "Everything is looking good! Awesome!",
  new Snackbar.Callback() {
      @Override
      public void onShown(Snackbar sb) {
          super.onShown(sb);
          // LGSnackbar is now visible
      }

      @Override
      public void onDismissed(Snackbar transientBottomBar, int event) {
          super.onDismissed(transientBottomBar, event);
          // LGSnackbar is now hidden
      }
});

Action:

LGSnackbarManager.show(SUCCESS, "Everything is looking good! Awesome!",
  new LGSnackbarAction("Action", new View.OnClickListener() {
     @Override
     public void onClick(View view) {
       // Action fired
     }
}));

Custom snackbar

If for any reason you may need to display a custom snackbar without setting a whole new theme, you can use an LGSnackbarBuilder

new LGSnackbar.LGSnackbarBuilder(getApplicationContext(), "This is a custom bar")
        .duration(Snackbar.LENGTH_LONG)
        .actionTextColor(Color.GREEN)
        .backgroundColor(Color.GRAY)
        .minHeightDp(50)
        .textColor(Color.WHITE)
        .iconID(R.drawable.ic_info_outline_white)
        .callback(null)
        .action(null)
        .show();
Supported Attributes
Attribute Description Default value
style An LGSnackBarStyle instance Native Android snackbar style
duration How long to display the message. Either LENGTH_SHORT or LENGTH_LONG LENGTH_LONG
backgroundColor The color of the snackbar Native Android color
actionTextColor The color of the text of an action Native Android color
textColor The color of the text white
minHeightDp The height of the snackbar when only one line if text is displayed 48
iconID The drawable id of the icon NO_ICON_ID (-1)
callback The snackbar callback null
action The snackbar action null

Issues

Feel free to submit issues and features requests.

Contributing

Contributions are more then welcome. Your contribution may include bug fixing, new features or just new themes.

Please follow the "fork-and-pull" Git workflow (check here for more).

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that I can review your changes

If you contribute with a new theme, please update also the themes.md file.

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Author

Lorenzo Greco

License

MIT License

Copyright (c) 2017 Lorenzo Greco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
This application is purpose to help user create todo activities.
This application is purpose to help user create todo activities.

To Do This application is purpose to help user create todo activities. Download App Features List Tasks Sort Tasks Add, Update and Delete Task Clean a

📲💬 react-native-fontext is a lightweight library to integrate fonts in your React Native application that works seamlessly in android and iOS devices.
📲💬 react-native-fontext is a lightweight library to integrate fonts in your React Native application that works seamlessly in android and iOS devices.

React Native Fontext react-native-fontext is a lightweight library to integrate fonts in your React Native application that works seamlessly in androi

A Python native extension written in Kotlin Native

Kotlin Python Ext This is a proof of concept for a Python extension in Kotlin. It is recommended to read the Official Python C API Documentation befor

Native-loader - Safely load native libraries in Java

Native Loader 📦️ Safe native loading in Java based off of the native-loader use

React-native-user-interface - Change React Native userinterface at runtime

react-native-user-interface change RN userinterface at runtime. Installation npm

A sample app that uses CameraX and Milkit to scan multiple barcodes and QR code
A sample app that uses CameraX and Milkit to scan multiple barcodes and QR code

MLKit-QR-and-Barcode-Scanner This sample app uses Firebase MLKit to scan bar codes and QR Codes There are a number of types of barcodes, MLKKIt is abl

A plugin for Termux to use native Android GUI components from CLI applications.

Termux:GUI This is a plugin for Termux that enables command line programs to use the native android GUI. In the examples directory you can find demo v

Membuat Multiple Marker dan Pencarian Lokasi dengan Android Studio
Membuat Multiple Marker dan Pencarian Lokasi dengan Android Studio

Multiple Marker Membuat Multiple Marker dan Pencarian Lokasi dengan Android Studio Tutorial Build with Android Studio https://youtu.be/6ZHbxZgps9A Tut

A pet project created to practise Android Development skills in Kotlin after finishing multiple courses online.

A pet project created to practise Android Development skills in Kotlin after finishing multiple courses online. The app displays a list of hundreds of characters provided by The Rick and Morty API https://rickandmortyapi.com/. In other screens user can access detailed information about a particular character, such as status, location and episodes. Libraries used in a project: - Kotlin - Jetpack libraries (Navigation, Room, Hilt, Palette) - other: Glide, Retrofit

Comments
  • The WindowManager is blocking any text input and even Back button on the background Acitivty.

    The WindowManager is blocking any text input and even Back button on the background Acitivty.

    To fix this, please change in 'LGSnackbarPresenter#createDefaultLayoutParams()' line 117

    layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

    opened by PeterSterba 1
  •  android.view.WindowManager$BadTokenException in Nougat

    android.view.WindowManager$BadTokenException in Nougat

    android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? at android.view.ViewRootImpl.setView(ViewRootImpl.java:679) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93) at greco.lorenzo.com.lgsnackbar.core.LGSnackbarPresenter.show(LGSnackbarPresenter.java:51) at greco.lorenzo.com.lgsnackbar.core.LGSnackbar.show(LGSnackbar.java:90) at greco.lorenzo.com.lgsnackbar.LGSnackbarManager.showSnackbar(LGSnackbarManager.java:91) at greco.lorenzo.com.lgsnackbar.LGSnackbarManager.show(LGSnackbarManager.java:86) at greco.lorenzo.com.lgsnackbar.LGSnackbarManager.show(LGSnackbarManager.java:70)

    I'm only getting this on Android 7 or above devices. Below 7, it's working fine.

    bug 
    opened by abhinashpati 10
Releases(1.0.2)
Owner
Lorenzo Greco
Software engineer with a background and passion for mobile technology.
Lorenzo Greco
Cody Engel 2 Apr 20, 2022
An easy-to-use wrapper for Lunar Client's game api.

An easy-to-use wrapper for Lunar Client's game api.

Patrick 5 Oct 25, 2022
Wrapper for Kustomer SDK v2.0 for react native

This is a wrapper for Kustomer v2 Sdk for react native. This implements the kust

Shivam Rawat 2 Dec 30, 2021
An library to help android developers working easly with activities and fragments (Kotlin version)

AFM An library to help android developer working easly with activities and fragments (Kotlin) Motivation Accelerate the process and abstract the logic

Massive Disaster 12 Oct 3, 2022
Android Package Inspector - dynamic analysis with api hooks, start unexported activities and more. (Xposed Module)

Inspeckage - Android Package Inspector Inspeckage is a tool developed to offer dynamic analysis of Android applications. By applying hooks to function

acpm 2.5k Jan 8, 2023
A beautiful app showing the use of a single recyclerview to display multiple views with motion layout and clean architecture

This app shows how to use a single recyclerview to build a beautiful multiple view layout (See image below) using clean architectural pattern

Ibrajix 62 Dec 26, 2022
Pass parameters safely and quickly between activities or fragments.

Bracer Pass parameters safely and quickly between activities or fragments. Read this in other languages: 中文, English, Change Log Prepare Add the JitPa

Season 57 Jan 3, 2023
An Android app for Dokuz Eylul University students can make use of multiple school websites in this one app

An Android app for Dokuz Eylul University students can make use of multiple school websites in this one app

Eyüb Salih Özdemir 3 Apr 13, 2022
A simple xposed module that helps you use your AdGuard subscription in multiple devices

DualGuard A simple xposed module that helps you use your AdGuard subscription in multiple (>3) devices. Monstor ahead! / 警告 This is NOT a module that

null 7 Oct 2, 2022
AnyText - An Xposed module trying to hook TextView in any activities

AnyText What's this This application provides features to modify any TextView in

Leonardo 41 Nov 30, 2022