A simple library to add custom toast to android app
Toaster-Android
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.
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:0.3.0'
}
How to use Toaster-Android
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.popError(
this,
"This is an error 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
- Create a toast buidler
val toastBuilder = Toaster.Builder(this)
.setMessage("File uploaded successfully")
.setLeftDrawable(R.drawable.ic_baseline_cloud_done_24)
.setLeftDrawableTint(R.color.blue)
.setStripTint(R.color.blue)
.setDuration(Toaster.LENGTH_SHORT)
- Add the builder to the
Toaster.pop
Toaster.pop(toastBuilder.make()).show()