Toasty library Kotlin variant with added sweetness of kotlin extensions.
This library was forked from Toasty and is a rewrite of same in kotlin with added kotlin extensions.
Add this in your root build.gradle
file (not your module build.gradle
file):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add this to your module's build.gradle
file (make sure the version matches the JitPack badge above):
dependencies {
...
implementation 'com.github.shubhamvashisht:KToasty:1.0'
}
Each method always returns a Toast
object, so you can customize the Toast much more. DON'T FORGET THE show()
METHOD!
For an error toast:
KToasty.error(yourContext, "This is an error toast.", Toast.LENGTH_SHORT, true).show()
For a success toast:
KToasty.success(yourContext, "Success!", Toast.LENGTH_SHORT, true).show()
For an info toast:
KToasty.info(yourContext, "Here is some info for you.", Toast.LENGTH_SHORT, true).show()
For an warning toast:
KToasty.warning(yourContext, "Beware of the dog.", Toast.LENGTH_SHORT, true).show()
For a normal toast:
KToasty.normal(yourContext, "Normal toast w/o icon").show()
For a normal toast with an icon:
KToasty.normal(yourContext, "Normal toast w/ icon", yourIconDrawable).show()
You can use extensions to quickly show the toasts. just call extensions on any context. For example. You don't need to call show() explicitly.
//normal toast
this.showNormalToast("message", Toast.LENGTH_SHORT)
//success toast with default icon
this.showSuccessToast("message", Toast.LENGTH_SHORT, true)
//normal toast
getActivity().showNormalToast("message", Toast.LENGTH_SHORT)
//error toast with default icon
getActivity().showErrorToast("error message", Toast.LENGTH_SHORT, true)
Please report and open issue if you find any. Contributions are always welcome. To contribute, simply open up a PR with the changes.