Skip to content

droidbyme/ToastLibrary

Repository files navigation

ToastLib

ToastLib is Library for Customize Toast.

Methods for implement

// ToastEnum.SHORT or ToastEnum.LONG
.duration(ToastEnum enum)

// Toast background color
.backgroundColor(int backgroundColor)

// Toast content textcolor
.textColor(int textColor)

// Toast content textsize (in SP), default is 20
.textSize(int size)

// Typeface for applying font to text
.typeface(Typeface ttf)

// true or false, for style bold to content
.isBold(boolean isBold)

// to apply fontAwesome icon, put fa-string in param
.icon(String faString)

// to add icon (drawable) in toast
.icon(int icon)

// to apply tint color on icon
.iconColor(int iconColor)

// icon size in dp, default is (24, 24)
.iconSize(int w, int h)

// corner radius for content, default is 4dp
.corner(int radius)

// margin from bottom/top (if Gravity is top then margin count from TOP and same for Bottom), default is 36
.margin(int margin)

// padding for inner content (default is 4)
.padding(int padding)

// space between icon and content, default is 8
.spacing(int spacing)

// toast UI stroke width and strokecolor
.stroke(int strokeWidth, int strokeColor)

// Gravity for placing toast (NOTE: .margin apply only for TOP and BOTTOM Gravity)
.gravity(int Gravity)

// to show toast
.show()

Usage
For Custom Toast
new ToastLib.Builder(this, "Login Success")
   .duration(ToastEnum.SHORT)
   .backgroundColor(ContextCompat.getColor(this, R.color.green))
   .textColor(ContextCompat.getColor(this, R.color.black))
   .textSize(18)
   .typeface(Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Regular.ttf"))
   .isBold(true)
   .icon(getString(R.string.fa_success))
   .icon(R.drawable.ic_check_black_24dp)
   .iconColor(ContextCompat.getColor(this, R.color.black))
   .iconSize(24, 24)
   .corner(8)
   .margin(56)
   .padding(36)
   .spacing(16)
   .stroke(2, ContextCompat.getColor(this, R.color.dark_green))
   .gravity(Gravity.BOTTOM)
   .show();
alt tag

For Success Toast
ToastLib.success(this, "Success", Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Regular.ttf"));
alt tag

For Error Toast
ToastLib.error(this, "Ooops! Try Again..", Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Regular.ttf"));
alt tag

For Loading/Progress Toast
ToastLib.progress(this, "Loading..", Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Regular.ttf"));
alt tag

About

Library for custom toast

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages