Displaying better toasts in Android using the TastyToast library

Learn how to display a beautiful android toast replacemente with the help of the TastyToast library in Android.

Displaying better toasts in Android using the TastyToast library

1. Install TastyToast

To install the TastyToast library in your Android project, modify the build.gradle file and add a new dependency, namely the tastytoast one:

dependencies {
    implementation 'com.sdsmdg.tastytoast:tastytoast:0.1.1'
}

After modifying, synchronize the project and start again. For more information about this library, please visit the official repository at Github here.

2. Displaying toasts

With TastyToast, you will be able to display 6 types of toasts namely for every ocassion:

  1. Success
  2. Warning
  3. Error
  4. Information
  5. Default
  6. Confusion

You just need to import the namespace on the class where you need it and cast the static makeText method of a the TastyToast class, provide the required parameters and that's it:

import com.sdsmdg.tastytoast.TastyToast;

// 1. Success message
TastyToast.makeText(
    getApplicationContext(), 
    "Success message !", 
    TastyToast.LENGTH_LONG, 
    TastyToast.SUCCESS
);

// 2. Warning message
TastyToast.makeText(
    getApplicationContext(), 
    "Warning message !", 
    TastyToast.LENGTH_LONG, 
    TastyToast.WARNING
);

// 3. Error message
TastyToast.makeText(
    getApplicationContext(), 
    "Error message !", 
    TastyToast.LENGTH_LONG, 
    TastyToast.ERROR
);

// 4. Info message
TastyToast.makeText(
    getApplicationContext(), 
    "Info message !", 
    TastyToast.LENGTH_LONG, 
    TastyToast.INFO
);

// 5. Default message
TastyToast.makeText(
    getApplicationContext(), 
    "Default message !", 
    TastyToast.LENGTH_LONG, 
    TastyToast.DEFAULT
);

// 6. Confusion message
TastyToast.makeText(
    getApplicationContext(), 
    "Confusion message !", 
    TastyToast.LENGTH_LONG, 
    TastyToast.CONFUSING
);


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.