Skip to content
Shivam Agrawal edited this page Sep 11, 2017 · 6 revisions

Welcome to the Android-CustomToast wiki!

1. Setup

Gradle dependency (recommended)

  • Add the following to your project level build.gradle:
allprojects {
	repositories {
		maven { url "https://jitpack.io" }
	}
}
  • Add this to your app build.gradle:
dependencies {
	compile 'com.github.shivam301296:Android-CustomToast:1.0.1'
}

Or use Maven

  • Add the following to the <repositories> section of your pom.xml:
<repository>
       <id>jitpack.io</id>
       <url>https://jitpack.io</url>
</repository>
  • Add the following to the <dependencies> section of your pom.xml:
<dependency>
       <groupId>com.github.shivam301296</groupId>
         <artifactId>Android-CustomToast</artifactId>
         <version>1.0.0</version>
</dependency>

2. Showing custom toast in your project

Either you can use predefined toast (Easy to call) or you can customize the toast

For using predefined Toast

Refer to the above table (Code and Output)

For using Custom Toast

new CT.Builder(this, "Your message")
            .textCol(Color.BLACK)
            .backCol(Color.YELLOW)
            .borderCol(Color.BLACK)
            .borderWidth(20)
            .image(R.drawable.apple)
            .gravity(Gravity.CENTER)
            .radius(80,0,0,80)
            .show();

Different methods and their use Apply there method to new CT.Builder(this, "Your message")

Method Use
textCol(int color) Set text color
backCol(int color Set background color
borderCol(int color) Set border color
borderWidth(int width Set border width
image(int imageResource) Set image in the toast
gravity(int gravityConstant) Set Toast gravity (Location)
radius(int topLeft, int topRight, int bottomLeft, int bottomRight), Set toast layout corner radius
shape(int shape) Set toast shape
duration(int duration) Set toast duration
show() Don't forget to call this method
Clone this wiki locally