Custom toasts with color and icon

Sometimes in Android, we need to notify the user with some instant information about the ongoing task which can be done via Toasts. By default, it only allows to show a text message but it can be fully customised according to our need. So, why there is a need of some library for this in-built function? Please read below to know more and find out the answer of this question.
Background
Android has toasts functionality but there is a possibility when it can be unnoticed by the user hence, may break user experience. It is a very basic feature and present in most of the Android apps. Similarly, I was also using it in one of my app which mostly performs task in the background and sometimes it notifies user about the current status of the app or task by displaying toasts which can easily be neglected due to no app related UI is visible to the user.
So, I have decided to make them slightly different from the system toasts which can be easily identified by the user. As a result, I have added color and icon functionality so that we can display different colors for different type of information and sometimes with icon also. For example, green color for success and red color for error. There are many other possibilities according to the requirement, read below to know more about their usage.
Usage
It has various methods to display toasts and can be customised to use in the different scenarios. This library is fully commented so I am highlighting some of the functions below. Please follow and keep exploring the official repo on GitHub to find out more hidden features.

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();Dependency
This library depends on the Dynamic Utils so, its functions can be used to perform other operations.
Conclusion
Did you have found the answer of the above question? As of now, you have an idea about the potential of this library. It has various possible ways to display toast messages in a simple but attractive manner. From icon to color, from text style to background, everything can be customized to give toasts a fun and material design overhaul.
So, Dynamic Toasts are useful or useful? I hope it will help you in your Android projects and please ask questions or share your feedback in the comments section to make it better.
Now, we have another powerful library along with the Dynamic Utils to make Android development as simple as possible. Stay tuned to know about the other packages of Dynamic Support (?…coming soon) library.
Originally published at techtics.xyz on July 22, 2017.
