在实际开发中,原本的Toast不能满足要求,无论是美观程度还是功能使用。
这里Android Studio第三方库栏目第一期,将对Toasty这一增强版Toast进行探索,以下是GitHub的连接:GitHub - GrenderG/Toasty: The usual Toast, but with steroids 💪The usual Toast, but with steroids 💪. Contribute to GrenderG/Toasty development by creating an account on GitHub.https://github.com/GrenderG/Toasty使用:首先在app目录下的build.gradle添加依赖:(在dependencies中添加代码)
dependencies { ... implementation 'com.github.GrenderG:Toasty:1.5.2' }
版本号本次使用的是1.5.2
官方案例:
报错提示
Toasty.error(yourContext, "This is an error toast.", Toast.LENGTH_SHORT, true).show();
成功提示
Toasty.success(yourContext, "Success!", Toast.LENGTH_SHORT, true).show();
info提示
Toasty.info(yourContext, "Here is some info for you.", Toast.LENGTH_SHORT, true).show();
警告提示
Toasty.warning(yourContext, "Beware of the dog.", Toast.LENGTH_SHORT, true).show();
通用提示
Toasty.normal(yourContext, "Normal toast w/o icon").show();
可以设置自定义提示小图标的提示
Toasty.normal(yourContext, "Normal toast w/ icon", yourIconDrawable).show();
Toasty.custom(yourContext, "I'm a custom Toast", yourIconDrawable, tintColor, duration, withIcon,
shouldTint).show();