File tree 1 file changed +11
-2
lines changed
utils/src/main/java/com/haoge/easyandroid/easy
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ class EasyToast private constructor(private val builder:Builder) {
38
38
private val context: Context = EasyAndroid .getApplicationContext()
39
39
private var toast: Toast ? = null
40
40
private var tv: TextView ? = null
41
+ private var container: View ? = null
41
42
42
43
fun show (resId : Int ) {
43
44
show(context.getString(resId))
@@ -60,6 +61,14 @@ class EasyToast private constructor(private val builder:Builder) {
60
61
}
61
62
}
62
63
64
+ /* * 获取Toast的View进行使用,只支持自定义样式的Toast,若为系统默认Toast样式,则返回null*/
65
+ fun getView ():View ? {
66
+ if (container == null && builder.isDefault.not ()) {
67
+ createToastIfNeeded()
68
+ }
69
+ return container
70
+ }
71
+
63
72
private fun showInternal (message : String ) {
64
73
createToastIfNeeded()
65
74
@@ -78,8 +87,8 @@ class EasyToast private constructor(private val builder:Builder) {
78
87
if (builder.isDefault) {
79
88
toast = Toast .makeText(context, " " , builder.duration)
80
89
} else {
81
- val container = builder.layout? : LayoutInflater .from(context).inflate(builder.layoutId, null )
82
- tv = container.findViewById(builder.tvId)
90
+ container = builder.layout? : LayoutInflater .from(context).inflate(builder.layoutId, null )
91
+ tv = container? .findViewById(builder.tvId)
83
92
toast = Toast (context)
84
93
toast?.view = container
85
94
toast?.duration = builder.duration
You can’t perform that action at this time.
0 commit comments