Toasty 一个自定义toast库
Toasty
这是一个自定义Toast的库。
效果图:
1. 添加这个在你的Project的 build.gradle 文件( 不是 你的Module的 build.gradle 文件):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
依赖
添加到你的Module的build.gradle文件:
dependencies {
...
compile 'com.github.GrenderG:Toasty:1.2.5'
}
配置
这一步是可选的,但如果你想要,你可以配置一些Toasty参数。把这个地方放在你的应用程序中
Toasty.Config.getInstance()
.setErrorColor(@ColorInt int errorColor) // optional
.setInfoColor(@ColorInt int infoColor) // optional
.setSuccessColor(@ColorInt int successColor) // optional
.setWarningColor(@ColorInt int warningColor) // optional
.setTextColor(@ColorInt int textColor) // optional
.tintIcon(boolean tintIcon) // optional (apply textColor also to the icon)
.setToastTypeface(@NonNull Typeface typeface) // optional
.setTextSize(int sizeInSp) // optional
.apply(); // required
To display an error Toast:
Toasty.error(yourContext, "This is an error toast.", Toast.LENGTH_SHORT, true).show();
To display a success Toast:
Toasty.success(yourContext, "Success!", Toast.LENGTH_SHORT, true).show();
To display an info Toast:
Toasty.info(yourContext, "Here is some info for you.", Toast.LENGTH_SHORT, true).show();
To display a warning Toast:
Toasty.warning(yourContext, "Beware of the dog.", Toast.LENGTH_SHORT, true).show();
To display the usual Toast:
Toasty.normal(yourContext, "Normal toast w/o icon").show();
To display the usual Toast with icon:
Toasty.normal(yourContext, "Normal toast w/ icon", yourIconDrawable).show();
You can also create your custom Toasts with the custom() method:
Toasty.custom(yourContext, "I'm a custom Toast", yourIconDrawable, tintColor, duration, withIcon,
shouldTint).show();
Github地址:https://github.com/GrenderG/Toasty
下载地址:Toasty-master.zip