ToastZ

欢迎来到ToastZ


[TOC]

https://github.com/duyangs/ToastZ

之前写过一个“ToastUtil” 让你的Toast更简单,近期对ToastUtil有进行了一些更新,最终出现了ToastZ。
ToastZ是一个可自定义的Toast,颇具个性,使用简洁而功能强大。优点请亲自体验,细节请阅读文档和源码。
由于目前ToastZ处于beta阶段,所以会较频繁更新,频繁程度在于你的 issues https://github.com/duyangs/ToastZ/issues

集成方式

  • Gradle

步骤1:将它添加到Project build.gradle 的根目录中:

1
2
3
4
5
6
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

步骤2.在module中添加dependency:

1
2
3
dependencies {
implementation 'com.github.duyangs:ToastZ:release'
}
  • Maven

步骤1. 添加JitPack repository到你的build file

1
2
3
4
5
6
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

步骤2. 添加dependency

1
2
3
4
5
<dependency>
<groupId>com.github.duyangs</groupId>
<artifactId>ToastZ</artifactId>
<version>release</version>
</dependency>

配置方式

  • 常规方式
1
ToastZLib.init(this)//初始化,Context
  • 进阶方式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//步骤一
ToastZLib.init(this)//初始化,Context

//步骤二
ToastZ.with().setGravity(Gravity.TOP)//设置Toast显示位置, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
.setSuccessColor(Color.parseColor("#909090"))//设置“成功”模式下 Toast背景颜色,@ColorInt
.setInfoColor(Color.parseColor("#909090"))//设置“提示”模式下 Toast背景颜色,@ColorInt
.setWarningColor(Color.parseColor("#909090"))//设置“警告”模式下 Toast背景颜色,@ColorInt
.setErrorColor(Color.parseColor("#909090"))//设置“错误”模式下 Toast背景颜色,@ColorInt
.setTextSize(16)//设置Toast文字大小,单位:sp
.setTextColor(Color.parseColor("#FFFFFF"))//设置Toast文字颜色,@ColorInt
.setToastTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL))//设置Toast字体,Typeface
.tintIcon(true)//设置是否显示Toast Icon,true or false
.apply()

//重置
ToastZ.with().reset()

使用方式

  • 常规方式
1
2
3
4
5
6
ToastZ.normal("normal")//只显示文字信息,无图标模式
ToastZ.success(R.string.success)//成功模式
ToastZ.warning("warning")//警告模式
ToastZ.error("error")//错误模式

ToastZ.cancelToast()//手动取消Toast
  • 进阶方式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//normal
ToastZ.normal(msg: Any)

ToastZ.normal(msg: Any, gravity: Int)

ToastZ.normal(msg: Any, gravity: Int, duration: Int)

ToastZ.normal(msg: Any, gravity: Int, duration: Int, icon: Drawable?)

/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param icon Icon of Toast, only Drawable
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.normal(msg: Any, gravity: Int, duration: Int, icon: Drawable?, withIcon: Boolean)

//success
ToastZ.success(msg: Any)

ToastZ.success(msg: Any, gravity: Int)

ToastZ.success(msg: Any, gravity: Int, duration: Int)

/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.success(msg: Any, gravity: Int, duration: Int, withIcon: Boolean)

//info
ToastZ.info(msg: Any)

ToastZ.info(msg: Any, gravity: Int)

ToastZ.info(msg: Any, gravity: Int, duration: Int)

/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.info(msg: Any, gravity: Int, duration: Int, withIcon: Boolean)

//warning
ToastZ.warning(msg: Any)

ToastZ.warning(msg: Any, gravity: Int)

ToastZ.warning(msg: Any, gravity: Int, duration: Int)

/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.warning(msg: Any, gravity: Int, duration: Int, withIcon: Boolean)

//error
ToastZ.error(msg: Any)

ToastZ.error(msg: Any, gravity: Int)

ToastZ.error(msg: Any, gravity: Int, duration: Int)

/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.error(msg: Any, gravity: Int, duration: Int, withIcon: Boolean)

//custom
ToastZ.custom(msg: Any, @DrawableRes icon: Drawable, @ColorInt tintColor: Int, duration: Int)

ToastZ.custom(msg: Any, gravity: Int, @DrawableRes icon: Drawable, @ColorInt tintColor: Int, duration: Int)

ToastZ.custom(msg: Any, gravity: Int, @DrawableRes icon: Drawable, @ColorInt tintColor: Int, duration: Int, withIcon: Boolean)

/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param iconRes Toast icon,only DrawableRes.
* @param tintColor Toast background color, only ColorInt.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
* @param shouldTint Whether to modify the Toast background,true or false.
*/
ToastZ.custom(msg: Any, gravity: Int, @DrawableRes iconRes: Int, @ColorInt tintColor: Int, duration: Int,
withIcon: Boolean, shouldTint: Boolean)

这只是个最简单示例,更多功能示例会逐渐补充

更多内容可查看源码https://github.com/duyangs/ToastZ,欢迎指正,希望对你有所帮助

您的支持将鼓励我继续创作!