Toast加强版Toasty简单使用

Toasty是一款用于Android应用的Toast样式库,可以轻松地为应用中的提示消息提供美观的样式定制。支持错误、成功、警告等多种类型的提示,并且可以通过简单的配置修改提示的颜色、字体大小等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GitHub地址:

https://github.com/GrenderG/Toasty

1. 添加这个在你的Project build.gradle 文件( 不是 你的Module build.gradle 文件):
allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

依赖

添加到你的Modulebuild.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();

拓展

You can pass formatted text to Toasty!

There are variants of each method, feel free to explore this library.

效果

Please click the image below to enlarge.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值