Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.Mani-Itachi:Toaster:1.0.0'
}
dependencies {
implementation("com.github.Mani-Itachi:Toaster:1.0.0")
}
<dependency>
<groupId>com.github.Mani-Itachi</groupId>
<artifactId>Toaster</artifactId>
<version>1.0.0</version>
</dependency>
libraryDependencies += "com.github.Mani-Itachi" % "Toaster" % "1.0.0"
:dependencies [[com.github.Mani-Itachi/Toaster "1.0.0"]]
Still using normal toast are you living under rock.
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.Mani-Itachi:Toaster:1.0.0'
}
<b>Normal toast:</b>
Toast.maketext(this,"This is a toast",Toast.LENGTH_SHORT).show();
<b>Toast with toaster:</b>
Toaster.maketext(this,"This is a toaster toast",Toast.LENGTH_SHORT).show();
What is the advantage? Hmm...
Toaster has some inbuilt methods that help you to customise your toasts
To display a normal Toast:
Toaster.makeText(this, "Hi! This is a sample toast",Toast.LENGTH_SHORT).show();
To display a Toast with an icon:
Toaster.makeText(this, "A toast with a cute cat",Toast.LENGTH_SHORT).setIcon(R.drawable.cat)
.setBackgroundColor(Color.parseColor("#FFFFFF"))
.setTextColor(Color.parseColor("#000000"))
.show();
To display a error Toast:
Toaster.error(this, "Oops! Error occurred",Toast.LENGTH_SHORT).show();
To display a success Toast:
Toaster.success(this, "Yay, it's a success",Toast.LENGTH_SHORT).show();
To display an info Toast:
Toaster.info(this, "Hey, here is some info",Toast.LENGTH_SHORT).show();
To display a warning Toast:
Toaster.warning(this, "This is a warning",Toast.LENGTH_SHORT).show();
You can further customise toast by calling other methods
Toaster.maketText(this,"Custom toast") -> returns a toaster object
setTextColor() -> change text color
setBackgroundColor() -> change the background color of the toast
setDuration() -> set the duration of the toast
setFont() -> change font of the toast
setGravity() -> change the position of the toast
setIcon() -> set an Icon for the toast
You can pass formatted text to toaster too 😎
Open an issue
so that you can be here.