Skip to content

5AbhishekSaxena/toaster-android

Repository files navigation

Toaster-Android

GitHub release (latest by date including pre-releases) GitHub GitHub (Pre-)Release Date Language

Toaster-Android is a simple open source library to customize toast messages in android applications. It has some predefined templates for common use-cases like warning, error and success messages.

Buy Me A Coffee

Download

Step 1

Add the JitPack repository to your build.gradle(project).

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

Step 2

Add the dependency to your build.gradle(Module: app).

dependencies {
  implementation 'com.github.5AbhishekSaxena.toaster-android:toaster:2.3.1'
  implementation 'com.github.5AbhishekSaxena.toaster-android:toaster-ktx:2.3.1' //for ktx support
}

Please Note: toaster-ktx includes toaster module so, if you are using toaster-ktx version then you don't have to add taoster

How to use Toaster-Android

Video:

A simple use case will look like this

Toaster.pop(
             this,
             "A simple toast message"
         ).show()

With a custom drawable

Toaster.pop(
              this,
              "A simple toast message with image",
              R.drawable.ic_baseline_cloud_done_24 /* image */
          ).show()

Code Snippets

Using templates
  • Success
	Toaster.popSuccess(
                  this,
                  "This is a success message",
                  Toaster.LENGTH_SHORT
              ).show()

  • Warning
	Toaster.popWarning(
              this,
              "This is a warning message",
              Toaster.LENGTH_SHORT
          ).show()

  • Error
	Toaster.popError(
              this,
              "This is an error message",
              Toaster.LENGTH_SHORT
          ).show()

Custom Toast
  1. Create a toast config
      val toastConfig = Toaster.Config(
              message = "File uploaded successfully",
              leftDrawableRes = R.drawable.ic_baseline_cloud_done_24,
              leftDrawableTint = R.color.blue,
              stripTint = R.color.blue,
              duration = Toaster.LENGTH_SHORT,
          )
  1. Add the config to the Toaster.pop
    Toaster.pop(toastConfig.make(context)).show()

Custom Toast (toaster-ktx)

With the toaster-ktx, you can either make Taoster or directly create Toast with the provided functions.

  1. Create Taoster and then poping it.
  • Create Taoster usign ktx
val toaster = prepareToaster(this) {
             message = "File uploaded successfully"
             leftDrawableRes = R.drawable.ic_baseline_cloud_done_24
             leftDrawableTint = R.color.blue
             stripTint = R.color.blue
             duration = Toaster.LENGTH_SHORT
         }
Toaster.pop(toaster).show()
  • Pop the Toast
Toaster.pop(toaster).show()
  1. Directly make Toast and show it
prepareToast(this) {
             message = "File uploaded successfully"
             leftDrawableRes = R.drawable.ic_baseline_cloud_done_24
             leftDrawableTint = R.color.blue
             stripTint = R.color.blue
             duration = Toaster.LENGTH_SHORT
 }.show()

Contributing

  • For contributions in this repository, please read Contribution guidelines for this project first. (Please pull the changes from this repo if you have already forked the repository and are facing conflicts)
  • If you like the repository, please star it.

License

MIT License. See the LICENSE file for details

Author

Abhishek Saxena