Skip to content

ToastView

DV Infosys edited this page Jun 26, 2019 · 1 revision

Configuration

This step is optional, but if you want you can configure some ToastView parameters. Place this anywhere in your app:

ToastView.Config.getInstance()
    .tintIcon(boolean tintIcon) // optional (apply textColor also to the icon)
    .setToastTypeface(@NonNull Typeface typeface) // optional
    .setTextSize(int sizeInSp) // optional
    .allowQueue(boolean allowQueue) // optional (prevents several Toastys from queuing)
    .apply(); // required

You can reset the configuration by using reset() method:

ToastView.Config.reset();

Usage

Each method always returns a Toast object, so you can customize the Toast much more. DON'T FORGET THE show() METHOD!

To display an error Toast:

ToastView.error(mContext, "This is an error toast.", Toast.LENGTH_SHORT, true).show();

To display a success Toast:

ToastView.success(mContext, "Success!", Toast.LENGTH_SHORT, true).show();

To display an info Toast:

ToastView.info(mContext, "Here is some info for you.", Toast.LENGTH_SHORT, true).show();

To display a warning Toast:

ToastView.warning(mContext, "Beware of the dog.", Toast.LENGTH_SHORT, true).show();

To display the usual Toast:

ToastView.normal(mContext, "Normal toast w/o icon").show();

To display the usual Toast with icon:

ToastView.normal(mContext, "Normal toast w/ icon", yourIconDrawable).show();

You can also create your custom Toasts with the custom() method:

ToastView.custom(mContext, "I'm a custom Toast", yourIconDrawable, tintColor, duration, withIcon, 
shouldTint).show();
Clone this wiki locally