In this blog, we’re going to discuss motion toast in android. Before going to implement the motion toast in android, first, let’s see what motion toast in android is.

If you are not familiar with what is a Toast in android, then go through my previous blog what is Toast in Android?

What is Motion Toast?

Dependency Project Level

Add it to your root build.gradle at the end of repositories:

allprojects {

repositories {

maven { url ‘https://jitpack.io' }

}

}

Dependency App Level

dependencies {

implementation ‘com.github.Spikeysanju:MotionToast:1.3.3.1

}

Types of Toast style

  • Motion Toast
  • Color Motion Toast
  • Dark Toast
  • Dark Color Toast

Toast Types

  1. TOAST_SUCCESS
  2. TOAST_ERROR
  3. TOAST_WARNING
  4. TOAST_INFO
  5. TOAST_DELETE

Toast Durations

  • LONG_DURATION : The toast message is stay for 4 seconds only
  • SHORT_DURATION : The toast message is stay for 2 seconds only

Usage

Sample Code for — Motion Toast

MotionToast.createToast(this,"Upload Completed!",MotionToast.TOAST_SUCCESS,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Error Toast

MotionToast.createToast(this,"Profile Update Failed!",MotionToast.TOAST_ERROR,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Warning Toast

MotionToast.createToast(this,"Please fill all the details!",MotionToast.TOAST_WARNING,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Info Toast

MotionToast.createToast(this,"This is information toast!",MotionToast.TOAST_INFO,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Sample Code for — Color Motion Toast

MotionToast.createColorToast(this,"Upload Completed!",MotionToast.TOAST_SUCCESS,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Error Toast

MotionToast.createColorToast(this,"Profile Update Failed!",MotionToast.TOAST_ERROR,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Warning Toast

MotionToast.createColorToast(this,"Please fill all the details!",MotionToast.TOAST_WARNING,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Info Toast

MotionToast.createColorToast(this,"This is information toast!",MotionToast.TOAST_INFO,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Sample Code for — Dark Toast

MotionToast.darkToast(this,"Upload Completed!",MotionToast.TOAST_SUCCESS,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Error Toast

MotionToast.darkToast(this,"Profile Update Failed!",MotionToast.TOAST_ERROR,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Warning Toast

MotionToast.darkToast(this,"Please fill all the details!",MotionToast.TOAST_WARNING,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Info Toast

MotionToast.darkToast(this,"This is information toast!",MotionToast.TOAST_INFO,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Sample Code for — Dark Color Toast

MotionToast.darkColorToast(this,"Upload Completed!",MotionToast.TOAST_SUCCESS,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Error Toast

MotionToast.darkColorToast(this,"Profile Update Failed!",MotionToast.TOAST_ERROR,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Warning Toast

MotionToast.darkColorToast(this,"Please fill all the details!",MotionToast.TOAST_WARNING,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Info Toast

MotionToast.darkColorToast(this,"This is information toast!",MotionToast.TOAST_INFO,MotionToast.GRAVITY_BOTTOM,MotionToast.LONG_DURATION,ResourcesCompat.getFont(this,R.font.helvetica_regular))

Example of Motion Toast

<?xml version=”1.0" encoding=”utf-8"?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android"
xmlns:app=”http://schemas.android.com/apk/res-auto"
xmlns:tools=”http://schemas.android.com/tools"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:gravity=”center_horizontal”
android:orientation=”vertical”
android:padding=”20dp”
tools:context=”.ToastActivtiy”
>

<
Button
android:id=”@+id/successToast”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/success_toast”
/>

<
Button
android:id=”@+id/errorToast”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/error_toast”
/>

<
Button
android:id=”@+id/warningToast”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/warning_toast”
/>

<
Button
android:id=”@+id/infoToast”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/info_toast”
/>

</
LinearLayout>

ToastActivty.java

package com.codewithgolap.fragment;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import www.sanju.motiontoast.MotionToast;

public class ToastActivtiy extends AppCompatActivity {

Button
successToast, errorToast, warningToast, infoToast;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.
activity_toast_activtiy);

successToast = findViewById(R.id.successToast);
errorToast = findViewById(R.id.errorToast);
warningToast = findViewById(R.id.warningToast);
infoToast = findViewById(R.id.infoToast);

successToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MotionToast.
Companion.createToast(ToastActivtiy.this,”Success Toast”,
MotionToast.
TOAST_SUCCESS,
MotionToast.
GRAVITY_BOTTOM,
MotionToast.
LONG_DURATION,
ResourcesCompat.
getFont(ToastActivtiy.this, R.font.helvetica_regular));
}
});

errorToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MotionToast.
Companion.createColorToast(ToastActivtiy.this,”Error Toast”,
MotionToast.
TOAST_ERROR,
MotionToast.
GRAVITY_BOTTOM,
MotionToast.
LONG_DURATION,
ResourcesCompat.
getFont(ToastActivtiy.this, R.font.helvetica_regular));
}
});

warningToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MotionToast.
Companion.darkToast(ToastActivtiy.this,”Warning Toast”,
MotionToast.
TOAST_WARNING,
MotionToast.
GRAVITY_BOTTOM,
MotionToast.
LONG_DURATION,
ResourcesCompat.
getFont(ToastActivtiy.this, R.font.helvetica_regular));
}
});

infoToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MotionToast.
Companion.darkColorToast(ToastActivtiy.this,”Info Toast”,
MotionToast.
TOAST_INFO,
MotionToast.
GRAVITY_BOTTOM,
MotionToast.
LONG_DURATION,
ResourcesCompat.
getFont(ToastActivtiy.this, R.font.helvetica_regular));
}
});
}

}

Output

Find it helpful? Let me know and show some love by following me and visit my website www.gbandroidblogs.com to know more about android related topics.

Keep Coding!!

Hi everyone, myself Golap an Android app developer with UI/UX designer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store