Introducing ToastLib v3.0.1 - A Modern Android Toast Library with Builder API

java dev.to

Android Toast messages are one of the simplest ways to show quick feedback to users.

But the default Android Toast often feels too basic when you are building a modern app.

That is why I created ToastLib.

ToastLib is a lightweight Android library that helps you show beautiful custom toast messages with icons, colors, different toast types, custom gravity, and a clean API.

With ToastLib v3.0.1, the library is now more flexible, more customizable, and easier to use in real Android projects.


What is ToastLib?

ToastLib is a custom Android toast library built for developers who want better looking feedback messages without writing the same custom toast layout again and again.

It supports ready-to-use toast types such as:

  • Success
  • Error
  • Info
  • Warning
  • Default

Example:

ToastLib.success(this, "Saved successfully");
ToastLib.error(this, "Something went wrong");
ToastLib.info(this, "Welcome back!");
ToastLib.warning(this, "Please check your input");
ToastLib.show(this, "Default toast message");
Enter fullscreen mode Exit fullscreen mode

Simple, clean, and easy to use.


Why ToastLib?

The default Android Toast works, but it is limited.

Toast.makeText(this, "Saved successfully", Toast.LENGTH_SHORT).show();
Enter fullscreen mode Exit fullscreen mode

This is fine for simple apps, but modern apps often need better UI feedback.

ToastLib solves this by providing:

  • Custom toast layouts
  • Built-in icons
  • Colored backgrounds
  • Multiple toast types
  • Android 11+ compatible custom toast UI
  • Easy static methods
  • Advanced builder API
  • Custom gravity and duration support

What is New in v3.0.1?

ToastLib v3.0.1 focuses on stability, better toast handling, and improved developer experience.

New Builder API

The new Builder API gives you more control over toast design and behavior.

ToastLib.builder(this)
        .setMessage("Profile updated successfully")
        .setType(ToastLib.ToastType.SUCCESS)
        .setGravity(Gravity.TOP)
        .setDuration(Toast.LENGTH_LONG)
        .show();
Enter fullscreen mode Exit fullscreen mode

This is useful when you want to customize toast behavior without creating multiple overloaded methods.


New Warning Toast

ToastLib now includes a warning toast type.

ToastLib.warning(this, "Please check your input");
Enter fullscreen mode Exit fullscreen mode

This is useful for form validation, incomplete data, permission warnings, and caution messages.


Basic Usage

Success Toast

ToastLib.success(this, "Saved successfully");
Enter fullscreen mode Exit fullscreen mode

Error Toast

ToastLib.error(this, "Something went wrong");
Enter fullscreen mode Exit fullscreen mode

Info Toast

ToastLib.info(this, "Welcome back!");
Enter fullscreen mode Exit fullscreen mode

Warning Toast

ToastLib.warning(this, "Please check your input");
Enter fullscreen mode Exit fullscreen mode

Default Toast

ToastLib.show(this, "Default toast message");
Enter fullscreen mode Exit fullscreen mode

Long Duration Toasts

ToastLib also includes helper methods for longer messages.

ToastLib.successLong(this, "Your changes have been saved successfully");
ToastLib.errorLong(this, "Unable to complete the request");
Enter fullscreen mode Exit fullscreen mode

Custom Position Toast

You can show toast messages at different positions.

ToastLib.show(
        this,
        "Top message",
        ToastLib.ToastType.INFO,
        Gravity.TOP
);
Enter fullscreen mode Exit fullscreen mode

Or use helper methods:

ToastLib.top(this, "Message from top");
ToastLib.center(this, "Centered toast message");
Enter fullscreen mode Exit fullscreen mode

Custom Builder Toast Example

Here is an example of a customized toast using the Builder API:

ToastLib.builder(this)
        .setMessage("Custom toast message")
        .setType(ToastLib.ToastType.SUCCESS)
        .setGravity(Gravity.BOTTOM)
        .setYOffset(180)
        .setDuration(Toast.LENGTH_LONG)
        .setHideIcon(false)
        .show();
Enter fullscreen mode Exit fullscreen mode

The Builder API makes ToastLib easier to extend and more useful for production apps.


Customization Support

ToastLib v3.0.1 supports:

  • Custom background color
  • Custom text color
  • Custom icon
  • Hide icon option
  • Icon tint support
  • Custom corner radius
  • Custom padding
  • Custom gravity
  • Custom X/Y offset
  • Short and long duration

This makes it easy to match the toast style with your app branding.


Installation

ToastLib is available through JitPack.

Step 1: Add JitPack Repository

Add JitPack in your settings.gradle or settings.gradle.kts.

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven("https://jitpack.io")
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Add ToastLib Dependency

If your GitHub release tag is v3.0.1, use:

dependencies {
    implementation 'com.github.TutorialsAndroid:Toast-Library:v3.0.1'
}
Enter fullscreen mode Exit fullscreen mode

For Kotlin DSL:

dependencies {
    implementation("com.github.TutorialsAndroid:Toast-Library:v3.0.1")
}
Enter fullscreen mode Exit fullscreen mode

Version Catalog Setup

If you are using Gradle Version Catalog, add this in libs.versions.toml:

[versions]
toastlib = "v3.0.1"

[libraries]
toastlib = { module = "com.github.TutorialsAndroid:Toast-Library", version.ref = "toastlib" }
Enter fullscreen mode Exit fullscreen mode

Then use it inside your app module:

dependencies {
    implementation(libs.toastlib)
}
Enter fullscreen mode Exit fullscreen mode

Backward Compatibility

Old code still works.

ToastLib.success(this, "Saved successfully");
ToastLib.error(this, "Something went wrong");
ToastLib.info(this, "Welcome back!");
ToastLib.show(this, "Default toast");
Enter fullscreen mode Exit fullscreen mode

So existing users can upgrade without rewriting their current implementation.


When Should You Use ToastLib?

ToastLib is useful when you want:

  • Better looking toast messages
  • Clean UI feedback
  • Success, error, info, warning, and default states
  • A simple API for beginners
  • A builder API for advanced customization
  • Android 11+ compatible custom toast UI
  • Lightweight integration without complex setup

GitHub Repository

You can check out the project here:

https://github.com/TutorialsAndroid/Toast-Library
Enter fullscreen mode Exit fullscreen mode

If you find this project useful, please consider giving it a star on GitHub.

It helps the project grow and motivates me to keep improving it.


Final Thoughts

ToastLib started as a simple Android toast helper library.

With v3.0.1, it is now more powerful, customizable, and production-ready.

If you are building an Android app and want modern toast messages with icons, colors, and clean API usage, ToastLib can save time and improve your app experience.

Thanks for reading.

Happy coding!

Source: dev.to

arrow_back Back to Tutorials