-
Notifications
You must be signed in to change notification settings - Fork 80
emotion toast api for Kotlin
vincent(朱志强) edited this page Jun 8, 2024
·
13 revisions
//string msg
SmartToast.emotion().info("当前网络良好")
//resource msg
SmartToast.emotion().info(R.string.net_fine)
//short toast
SmartToast.emotion().warning("电量过低,请尽快充电")
//short toast
SmartToast.emotion().warning(R.string.power_low)
//short toast
SmartToast.emotion().success("删除成功")
//short toast
SmartToast.emotion().success(R.string.delete_succ)
//short toast
SmartToast.emotion().error("数据解析出错")
//short toast
SmartToast.emotion().error(R.string.data_parse_error)
//short toast
SmartToast.emotion().fail("保存失败")
//short toast
SmartToast.emotion().fail(R.string.save_fail)
//short toast
SmartToast.emotion().complete("下载完成")
//short toast
SmartToast.emotion().complete(R.string.download_complete)
//short toast
SmartToast.emotion().forbid("当前账户不允许汇款操作")
或者,
//short toast
SmartToast.emotion().forbid(R.string.forbid_op)
//short toast
SmartToast.emotion().waiting("已在后台下载,请耐心等待")
或者,
//short toast
SmartToast.emotion().waiting(R.string.wait_to_download)
需要配置风格时,调用config()
方法,配置结束后,调用commit
方法生效
SmartToast.emotion()
.config()
.backgroundDrawable(drawable)
.commit()
.info("I'm a toast")
或者,
SmartToast.emotion()
.config()
.backgroundResource(R.drawable.toast_bg)
.commit()
.info("I'm a toast")
回到目录导航
配置颜色,并不会替换默认的背景drawable,只会替换其填充色
SmartToast.emotion()
.config()
.backgroundColor(Color.BLUE)
.commit()
.info("I'm a toast")
或者,
SmartToast.emotion()
.config()
.backgroundColorResource(R.color.colorPrimary)
.commit()
.info("I'm a toast")
SmartToast.emotion()
.config()
//颜色,大小,是否加粗
.messageStyle(Color.WHITE, 14f, false)
.commit()
.info("I'm a toast")
回到目录导航
不设置Icon则为默认的Icon
SmartToast.emotion()
.config()
.iconDrawable(drawable)
.commit()
.info("I'm a toast")
或者,
SmartToast.emotion()
.config()
.iconResource(R.drawable.ic_custom_icon)
.commit()
.info("I'm a toast")
SmartToast.emotion()
.config()
.iconSize(30f)
.commit()
.info("I'm a toast")
SmartToast.emotion()
.config()
.marginBetweenIconAndMsg(10f)
.commit()
.info("I'm a toast")
SmartToast.emotion()
.config()
.duration(Duration.of(5000))
.commit()
.info("custom duration")
duration方法的参数必须是Duration对象,有三个内置值:
-
Duration.SHORT
2s的toast,也是不配置duration时的默认值 -
Duration.LONG
,3.5s的toast -
Duration.INDEFINITE
一直展示,直到被下一个toast覆盖,或主动调用SmartToast.dismiss()方法关闭
此外,可通过Duration.of
方法,获取任意时长的Duration,单位为毫秒
Duration.of(5000)
1