18034727885
2026-04-27 3a4c1bbb2cf4fb1cdda8a5061b0674f30e7456b4
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
package com.example.basecore.util
 
import android.content.Context
import android.widget.Toast
import androidx.annotation.StringRes
 
/**
 * Created by dai
 * on 2019/11/23
 */
 
var mToast: Toast? = null
 
fun Context.showOnlyToast(content: String) {
    if (mToast == null) {
        mToast = Toast.makeText(this, content, Toast.LENGTH_SHORT)
    } else {
        mToast?.setText(content)
        mToast?.duration = Toast.LENGTH_SHORT
    }
    mToast?.show()
}
 
fun Context.toast(content: String, duration: Int = Toast.LENGTH_SHORT) {
    Toast.makeText(this, content, duration).apply {
        show()
    }
}
 
fun Context.showCenterToast(content: String) {
    ToastUtils.showToast(this, content)
}
 
fun Context.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_SHORT) {
    toast(getString(id), duration)
}
 
fun Context.longToast(content: String) {
    toast(content, Toast.LENGTH_LONG)
}
 
fun Context.longToast(@StringRes id: Int) {
    toast(id, Toast.LENGTH_LONG)
}
 
fun Any.toast(context: Context, content: String, duration: Int = Toast.LENGTH_SHORT) {
    context.toast(content, duration)
}
 
fun Any.toast(context: Context, @StringRes id: Int, duration: Int = Toast.LENGTH_SHORT) {
    context.toast(id, duration)
}
 
fun Any.longToast(context: Context, content: String) {
    context.longToast(content)
}
 
fun Any.longToast(context: Context, @StringRes id: Int) {
    context.longToast(id)
}