ToastBox是一个自定义吐司库,可以实现自定义View、显示时长、显示位置、各种自定义风格。有WindowsManger和系统Toast两种实现方式,配合Lottie动画库可以做一些好看的toast
success:
fail:
网络错误:
普通信息:
Lottie中有很多看好的动画,你也可以自己设计一个。
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.xluu233:ToastBox:0.5.1'
}
stetup1: 在Application中初始化
ToastBoxRegister.init(this)
初始化时可以配置一些参数
ToastBoxRegister.init(this).apply {
//text样式:白色和灰色
textStyle = TextStyle.White
//可以设置默认显示图标
defaultIcon = R.drawable.ic_launcher_background
//设置默认动画
animStyle = R.style.xxx
}
setup2:简单调用
ToastBox(this).show("This is ToastBox")
//正常使用
ToastBox().show("This is ToastBox")
//在不同的位置弹出
ToastBox().setLocation(Location.TOP).show("TOP ToastBox")
ToastBox().setLocation(Location.CENTER).show("Center ToastBox")
ToastBox().setLocation(Location.BOTTOM).show("Bottom ToastBox")
//修改透明度
ToastBox().setLocation(Location.CENTER).setAlpha(0.5f).show("Center ToastBox")
//自定义布局,传入View或者layout
ToastBox().setView(R.layout.custom_toast_common_1).show("This is Custom View",5000L)
//设置toast时间
ToastBox().show("5000L",duration = 5000)
//设置xy必须在设置location后面
ToastBox().setLocation(Location.BOTTOM).setXY(100,200).show("Center ToastBox")
//设置监听
ToastBox().setListener(object : ToastClickItf{
override fun setOnToastDismissed() {
xLog.d(TAG,"toast dismissed")
}
}).show("哈啊啊啊啊啊哼哼",3000L)
//不同风格的toast
ToastBox().setTextStyle(TextStyle.GRAY).show("灰色Toast")
ToastBox().setTextStyle(TextStyle.White).setXY(0,300).show("白色Toast")
ToastBox().setTextStyle(TextStyle.Black).setXY(0,600).show("黑色Toast")
//设置动画
ToastBox().setAnim(R.style.MiuiToast).show("切换弹出动画")
//自定义图标
ToastBox().setIcon(R.drawable.icon).show("This is ToastBox")
卑微Androider求一个Star*
相关文章:
写一个MVVM快速开发框架(一)基础类封装