An Android Toast replacement, similar to the one seen in the GMail app.

Related tags

Toast MessageBar
Overview

MessageBar

An Android Toast replacement, similar to the one seen in the GMail app. Multiple messages can be posted in succession, and each message will be shown for 5 seconds.

Usage

There's two ways to use the MessageBar. It can either be attached directly to an activity, or a View can be passed.

Attaching to an activity

This approach requires adding the following attributes to the Activity's theme.

<item name="messageBarContainerStyle">@style/MessageBar.Container</item>
<item name="messageBarTextStyle">@style/MessageBar.Message</item>
<item name="messageBarButtonStyle">@style/MessageBar.Button</item>

Attaching the MessageBar is then done by passing the Activity to the MessageBar constructor.

mMessageBar = new MessageBar(this);

This will automatically add a MessageBar layout to the content view.

Attaching to a View

This can be used e.g. when attaching to a Fragment, or if custom views are to be used for showing the message.

When using this approach, child views with the following id's must be added to the passed View.

  • mbContainer: The container that holds the message and the button views.
  • mbMessage: A TextView that displays the message.
  • mbButton: A TextView that displays the button text.

As an example, this is the default layout that's used when attaching to an Activity.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/mbContainer"
    style="?attr/messageBarContainerStyle">

    <TextView
        android:id="@id/mbMessage"
        style="?attr/messageBarTextStyle" />

    <TextView
        android:id="@id/mbButton"
        style="?attr/messageBarButtonStyle" />
</LinearLayout>

The MessageBar is then attached by passing a parent view to the constructor.

Showing a message

A message is shown simple by calling MessageBar#show(...). A few methods are available here. It can either simply show a message or show a message and a button. When a button is shown, a Parcelable has to be passed that's then returned via MessageBar$OnMessageClickListener if the button is clicked.

Example:

mMessageBar.show("This is a message");

Credits

  • Roman Nurik for creating the example this library is based on.

License

Copyright 2012 Simon Vig Therkildsen

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
  • Issue when using with Support Library v7

    Issue when using with Support Library v7

    Calling MessageBar messageBar = new MessageBar(this); from an activity extending ActionBarActivity (Support Library v7) gives an XML Inflating error:

    Binary XML file line #25: Error inflating class android.support.v7.internal.widget.ActionBarView

    It seems that by "injecting" the message layout into the activity layout breaks the ActionBarView layout, thus causing the error.

    I've tried the same with a regular activity and it works. Can you give it a try and see if it works on your side?

    opened by mradzinski 2
  • Switching back to a Fragment sees an bottom empty MessageBar that never disappears.

    Switching back to a Fragment sees an bottom empty MessageBar that never disappears.

    I embed the MessageBar in an Fragment. It works fine at first. But when I switch out and in to the same Fragment again. An empty MessageBar displays at the bottom of the screen and never disappears. I have no clue how to fix this.

    Is it because in Fragment you can't construct a MessageBar instance using MessageBar mb = new MessageBar(getActivity()); ? I note in the doc it says that in Fragment you have to use a different method. But after following the doc and run the app, it crashes and reports a bug in init() of MessageBar saying that "layout_width" attribute not provided...

    In the sample I noticed that there is no demo showing how to use one in Fragment. Would you please complete the demo? Thank you!

    opened by dannysunyu 1
  • MessageBar is not able to show above or infront of an AlertDialog's dimmed background.

    MessageBar is not able to show above or infront of an AlertDialog's dimmed background.

    As the title stats, when an AlertDialog is showing and MessageBar(...) is called, the MessageBar is always displayed behind the dimmed background of the AlertDialog.

    I think this has to be fixed because a Toast is able to be displayed above/infront of an AlertDialog.

    I tried playing around with the internal mContainer View by calling the View.bringToFront() method, but that didn't work either.

    opened by Hassaan 1
  • It doesn't work

    It doesn't work

    It doesn't work. The log shows that NullPointerException occurs at "new MessageBar(this)" in the sample project. I don't understand why. My device is Samsung GT-7562. Does anybody other encounter trouble like this?

    opened by bytebeats 0
  • Dismiss listener and property hide delay

    Dismiss listener and property hide delay

    Hello @SimonVT,

    Thanks for this amazing lib!

    I suggest creating a OnMessageDismissListener, fired when the message will be faded out, and with OnMessageClickListener allow commiting or rolling-back a transaction.

    Other idea is changing the hide delay to a property, allowing configure the hide delay. Could be useful in some cases, for accessibility, e.g.

    opened by geovanisouza92 0
  • Button only mode

    Button only mode

    You handle the case that the actionMessage is null and only show the text in that case. Could you also add the opposite? If the message is null, the button will take the full width of the MessageBar.

    opened by gabrielittner 0
  • NPE after onClick

    NPE after onClick

    I was clicking the button on the toast during the fade out animation and I got this:

      E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: net.simonvt.messagebar.samples, PID: 3073
    java.lang.NullPointerException
            at net.simonvt.messagebar.samples.SampleActivity.onMessageClick(SampleActivity.java:67)
            at net.simonvt.messagebar.MessageBar$2.onClick(MessageBar.java:151)
            at android.view.View.performClick(View.java:4456)
            at android.view.View$PerformClick.run(View.java:18462)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5102)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
    
    opened by DanielNovak 0
  • Allow passing a style in

    Allow passing a style in

    This is a neat library, but one thing that would really make it more useful is the ability to pass in a style. For example, maybe I want red messagebars for errors.. green for confirmations.. and grey for general messages?

    Theres no easy way to mix and match right now, because you're tied to what you do in the style that you declare for the activity.

    opened by inktomi 0
This custom snack bar will help you display much more personalized app toast

?? Presentation Using the native android class of snack bar. This custom snack bar will help you display much more personalized app

Xavi 4 Dec 8, 2022
Android : IamToast Another Toast library for Android

Android : IamToast Another Toast library for Android Warning. toast custom view is deprecated since android 11(R) Setup allprojects { repositories

null 2 Jun 12, 2022
A library that extends the Android toast framework.

SuperToasts Library The SuperToasts library enhances and builds upon the Android Toast class. This library includes support for context sensitive Supe

John Persano 2.7k Dec 29, 2022
In-layout notifications. Based on Toast notifications and article by Cyril Mottier (http://android.cyrilmottier.com/?p=773).

Android AppMsg (Crouton) Library Implementation of in-layout notifications. Based on Toast notifications and article The making of Prixing #4: in-layo

Evgeny Shishkin 1.4k Nov 25, 2022
🍞 The missing toast library for Android.

Literally Toast ?? A toast library for Android. Usage: ?? Use the LitToast to get lit and show your users a proper toast. LitToast.create(context, "My

David Voiss 229 Nov 25, 2022
Toastie is a customizable Android toast library.

Toastie Getting Started Gradle Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories: Note

Burak Fidan 36 Apr 3, 2021
Android Custom Toast

Super Toast Library Written Purely in Kotlin ❤️ Usual Toast but with super powers!!! ?? A Fully Customised and Customisable Toast. ]( https://android-

null 26 Dec 27, 2022
Android Toast For RTL Applications

RTL-Toast Android library to show Toasts in a pretty RTL way Install Add it in your root build.gradle allprojects { repositories { ... ma

Arash Hatami 15 Nov 16, 2022
Attractive, stylish and customizable toast library for Android.

FabToast min SDK 16 (Jelly Bean 4.1) written in Java To download the demo app for this library from Google Playstore so you can see it in action, clic

Dean Spencer 11 Feb 14, 2022
Customizable toast message library for Android

Android Custom Toast Message (SnToast) Customizable Toast Message Library For Android Add this in your root build.gradle file allprojects { reposito

null 9 Nov 15, 2021
The usual Toast, but with steroids 💪

Toasty The usual Toast, but with steroids. Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { r

null 6.4k Jan 9, 2023
A really simple library that help you to display a custom toast with many colors (for : success, warning, danger, info, dark, light, primary...etc ), or with rounded corners, or event with image.

CoolToast A really simple library that help you to display a custom toast with many colors (for : success, warning, danger, info, dark, light, primary

null 21 Dec 20, 2022
Simple toast

newlibrary Simple toast Step 1. Add the JitPack repository to your build file allprojects { repositories { ... maven { url 'https://jitpack.io

Aziz Developer 0 Nov 5, 2021
An easy, flexible way to have the toast message displayed.

IToaster Library An easy, flexible way to have the toast message displayed. Download Gradle Add below codes to your root build.gradle file (not your m

Evans Kiptarus Kibet 1 Mar 19, 2022
Custom Toast Library by Google Developer Student Club University of Brawijaya

GDSCToast Custom Toast Library by Google Developer Student Club University of Brawijaya Prerequisites For old version of gradle (before arctic fox upd

Kylix Eza S 6 Sep 15, 2022
MDToast - MaterialDesign Toast library written with Kotlin with lots of extensions to interact easily in contexts

MDToast - MaterialDesign Toast A lightweight Toast library written with Kotlin i

Morteza Omar Mohammady 12 Dec 23, 2022
Android library to create customizable floating animated toasts like in Clash Royale app

FloatingToast-Android An android library to make customisable floating animated toasts Getting Started In your build.gradle dependencies { impleme

Hariprasanth S 96 Dec 30, 2022
An android library for easy implementation of Toasts in Android with easy customisation.

ToastTypeDecore ©️ A library for easy implementation of Toasts in Android with easy customisation. Latest Version : v2.1 Screenshots Success Toast1 Su

Aditya Bavadekar 1 Jul 7, 2022
Context sensitive notifications for Android

Crouton Context sensitive notifications for Android DEPRECATION NOTICE This library has passed it's prime and is now considered deprecated. With the A

Ben Weiss 3k Dec 28, 2022