Custom toasts with color and icon for Android.

Last update: May 10, 2022

Dynamic Toasts

License Build Status Download

A simple library to display themed toasts with icon and text on Android 2.3 (API 9) and above devices.

Since v0.4.0, it uses 26.x.x support libraries so, minimum SDK will be Android 4.0 (API 14).
Since v2.0.0, it uses AndroidX so, first migrate your project to AndroidX.


Contents


Installation

It can be installed by adding the following dependency to your build.gradle file:

dependencies {
    // For AndroidX enabled projects.
    implementation 'com.pranavpandey.android:dynamic-toasts:3.3.1'

    // For legacy projects.
    implementation 'com.pranavpandey.android:dynamic-toasts:1.3.0'
}

Usage

It has several method to display toasts based on the requirement. Each method returns a Toast object which can be customised further.

Please call show() method to display the toast.

For complete reference, please read the documentation.

Configuration

Optional configuration to customise the toasts further like custom background color or drawable, custom text size, typeface or icon size, etc.

Various methods can be called anywhere in the app to do customisations.

DynamicToast.Config.getInstance()
    // Background color for default toast.
    .setDefaultBackgroundColor(@ColorInt int defaultBackgroundColor)
    // Tint color for default toast.
    .setDefaultTintColor(@ColorInt int defaultTintColor)
    // Background color for error toast.
    .setErrorBackgroundColor(@ColorInt int errorBackgroundColor)
    // Background color for success toast.
    .setSuccessBackgroundColor(@ColorInt int successBackgroundColor)
    // Background color for warning toast.
    .setWarningBackgroundColor(@ColorInt int warningBackgroundColor)
    // Custom icon for error toast. Pass `null` to use default icon.
    .setErrorIcon(@Nullable Drawable errorIcon)
    // Custom icon for success toast. Pass `null` to use default icon.
    .setSuccessIcon(@Nullable Drawable successIcon)
    // Custom icon for warning toast. Pass `null` to use default icon.
    .setWarningIcon(@Nullable Drawable warningIcon)
    // Disable icon for all the toasts.
    .setDisableIcon(boolean disableIcon)
    // Custom icon size in `pixels` for all the toasts.
    .setIconSize(int iconSize)
    // Custom text size in `SP` for all the toasts.
    .setTextSize(int textSize)
    // Custom text typeface for all the toasts. Pass `null` to use system typeface.
    .setTextTypeface(@Nullable Typeface textTypeface)
    // Custom background drawable for all the toasts. Pass `null` to use default background.
    .setToastBackground(@Nullable Drawable toastBackground)
    // Apply customisations.
    .apply();

Call reset() method to reset all the customisations.

// Reset customisations.
DynamicToast.Config.getInstance().reset();

Default toast

Simple toast based on the vanilla Android theme for Toast.LENGTH_SHORT duration.

DynamicToast.make(context, "Default toast").show();

Default toast with duration

Simple toast based on the vanilla Android theme for supplied duration.

DynamicToast.make(context, "Default toast with duration", duration).show();

Default toast with icon

Simple toast based on the vanilla Android theme with a icon for Toast.LENGTH_SHORT duration.

DynamicToast.make(context, "Default toast with icon", drawable).show();

Default toast with icon and duration

Simple toast based on the vanilla Android theme with a icon for supplied duration.

DynamicToast.make(context, "Default toast with icon and duration", drawable, duration).show();

Error toast

Error toast with #F44336 background for Toast.LENGTH_SHORT duration.

DynamicToast.makeError(context, "Error toast").show();

Error toast with duration

Error toast with #F44336 background for supplied duration.

DynamicToast.makeError(context, "Error toast with duration", duration).show();

Success toast

Success toast with #4CAF50 background for Toast.LENGTH_SHORT duration.

DynamicToast.makeSuccess(context, "Success toast").show();

Success toast with duration

Success toast with #4CAF50 background for supplied duration.

DynamicToast.makeSuccess(context, "Success toast with duration", duration).show();

Warning toast

Warning toast with #FFEB3B background for Toast.LENGTH_SHORT duration.

DynamicToast.makeWarning(context, "Warning toast").show();

Warning toast with duration

Warning toast with #FFEB3B background for supplied duration.

DynamicToast.makeWarning(context, "Warning toast with duration", duration).show();

Custom toast

Custom toast based on the supplied background and tint color for Toast.LENGTH_SHORT duration.

DynamicToast.make(context, "Custom toast", tintColor, backgroundColor).show();

Custom toast with duration

Custom toast based on the supplied background and tint color for supplied duration.

DynamicToast.make(context, "Custom toast with duration", tintColor, backgroundColor, duration).show();

Custom toast with icon

Custom toast based on the supplied icon, background and tint color theme for Toast.LENGTH_SHORT duration.

DynamicToast.make(context, "Custom toast with icon", drawable, tintColor, backgroundColor).show();

Custom toast with icon and duration

Custom toast based on the supplied icon, background and tint color theme for supplied duration.

DynamicToast.make(context, "Custom toast with icon and duration", drawable, 
        tintColor, backgroundColor, duration).show();

Cheat sheets

Use dynamic hint to display cheat sheets for any view. All the methods are same as explained above, just replace DynamicToast with DynamicHint to create a cheat sheet.

Use DynamicHint.show(view, toast) method to display it according to the anchor view position.

Dependency

It depends on the dynamic-utils to perform various internal operations. So, its functions can also be used to perform other useful operations.


Author

Pranav Pandey

GitHub Follow on Twitter Donate via PayPal


License

Copyright 2017-2021 Pranav Pandey

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.

GitHub

https://github.com/pranavpandey/dynamic-toasts
You might also like...

Context sensitive notifications for Android

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

May 11, 2022

A library that extends the Android toast framework.

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

May 13, 2022

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

MessageBar An Android Toast replacement, similar to the one seen in the GMail app. Multiple messages can be posted in succession, and each message wil

Feb 16, 2022

🍞 The missing toast library for Android.

🍞 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

Dec 17, 2021

Toastie is a customizable Android toast library.

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

Apr 3, 2021

Android Toast For RTL Applications

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

Oct 19, 2021

A tooltip/showcase library for Android re-written in Kotlin.

UglyTooltip Based on another Showcase library. Being kotlinized, customized and refactored.

Apr 27, 2022

Customizable toast message library for Android

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

Nov 15, 2021

BiometricAuth - A simple project to show biometric authenticaation in android

BiometricAuth - A simple project to show biometric authenticaation in android

BiometricAuth a simple project to show biometric authenticaation in android link

Feb 16, 2022
Comments
  • 1. Not working

    Dear @pranavpandey

    I am trying to use this framework in order to create a toast error message,

                        DynamicToast.makeError(context, "Email or Password not valid").show();
    

    but this is the error I got:

    E/AndroidRuntime: FATAL EXCEPTION: main
                      Process: com.example.vaevictis.myapplication, PID: 10187
                      java.lang.NoClassDefFoundError: Failed resolution of: Lcom/pranavpandey/android/dynamic/utils/DynamicColorUtils;
                          at com.pranavpandey.android.dynamic.toasts.DynamicToast.makeError(DynamicToast.java:241)
                          at com.example.vaevictis.myapplication.user.UserController$1.onResponse(UserController.java:49)
                          at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
                          at android.os.Handler.handleCallback(Handler.java:751)
                          at android.os.Handler.dispatchMessage(Handler.java:95)
                          at android.os.Looper.loop(Looper.java:154)
                          at android.app.ActivityThread.main(ActivityThread.java:6121)
                          at java.lang.reflect.Method.invoke(Native Method)
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
                       Caused by: java.lang.ClassNotFoundException: Didn't find class "com.pranavpandey.android.dynamic.utils.DynamicColorUtils" on path: DexPathList[[zip file "/data/app/com.example.vaevictis.myapplication-1/base.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.vaevictis.myapplication-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.vaevictis.myapplication-1/lib/arm64, /system/lib64, /vendor/lib64]]
                          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                          at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                          at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                          at com.pranavpandey.android.dynamic.toasts.DynamicToast.makeError(DynamicToast.java:241) 
                          at com.example.vaevictis.myapplication.user.UserController$1.onResponse(UserController.java:49) 
                          at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70) 
                          at android.os.Handler.handleCallback(Handler.java:751) 
                          at android.os.Handler.dispatchMessage(Handler.java:95) 
                          at android.os.Looper.loop(Looper.java:154) 
                          at android.app.ActivityThread.main(ActivityThread.java:6121) 
                          at java.lang.reflect.Method.invoke(Native Method) 
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 
    
    

    Any clue of what can cause the problem?

    Reviewed by FrancescoSaverioZuppichini at 2017-12-01 09:06
  • 2. update a toast

    how can update a DynamicToast? i have multiple toast and we need to show it in default of dynamic toast it show consequently and for example for 10 toast it show for 1 minute and one by one. but we need update last toast to new toast text and style. how can i do this?

    Reviewed by Mahdiazadbar at 2018-04-29 15:06
  • 3. No static method getFont

    Hello Dear i want to use this library in my project . add in to dependencies and sync successfully . and use this command in my project like this : DynamicToast.makeError(getApplicationContext(), "Error Message", Toast.LENGTH_SHORT).show();

    and after run project , i faced "unfortunately app has stopped" . after that i read logs and see this error :

    FATAL EXCEPTION: main Process: com.example.mohammad_pc.crm_android,PID:29510java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of 'android.support.v4.content.res.ResourcesCompat' appears in /data/app/com.example.mohammad_pc.crm_android-1/base.apk)

    what is this ? guide me please thank you

    Reviewed by mrmosi13 at 2018-03-03 13:06
  • 4. Request: support Android 11 (R - API 31)

    Sadly on Android R, you can't set a custom View for a Toast (when targeting API 31) :

    https://developer.android.com/reference/android/widget/Toast#setView(android.view.View) https://developer.android.com/reference/android/widget/Toast#getView()

    Please offer something that mimics the standard Toast's look&feel, so that at least we could have it shown within the app, as a normal View. Maybe something similar to what we have when we long press the action items on the toolbar:

    dfu6CwFaPM.zip

    Custom Toasts are useful anyway usually only when the user is inside the app...

    Reviewed by AndroidDeveloperLB at 2020-11-28 14:04
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

Mar 9, 2022
Pretty material design toasts with feedback animations
Pretty material design toasts with feedback animations

Load Toast Library The default toasts are ugly and don't really provide much more than a short message. This small library provides a better toast whi

May 10, 2022
CuteToast is an Material Design Custom Toast for Android | Custom Material Design Toast
CuteToast is an Material Design Custom Toast for Android | Custom Material Design Toast

CuteToast is an Android Custom Toast library that could be used instead of Default Toast. It does everything as Toast but with some extra spice.

Dec 14, 2021
Android Custom Toast
Android Custom Toast

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

May 2, 2021
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

Jun 22, 2020
Custom Toast Library by Google Developer Student Club University of Brawijaya
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

May 22, 2022
In-layout notifications. Based on Toast notifications and article by Cyril Mottier (http://android.cyrilmottier.com/?p=773).
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

May 19, 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

Feb 14, 2022
Balloon 🎈 A lightweight popup like tooltips, fully customizable with arrow and animations.
Balloon  🎈 A lightweight popup like tooltips, fully customizable with arrow and animations.

Balloon ?? A lightweight popup like tooltips, fully customizable with arrow and animations.

May 20, 2022
Android : IamToast Another Toast library for Android
 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

Feb 7, 2022