Files
BirdsProject/app/src/main/java/com/juhabi/birds/util/ToastUtil.kt
2026-09-17 08:59:24 +08:00

44 lines
1.1 KiB
Kotlin

package com.juhabi.birds.util
import android.content.Context
import android.widget.Toast
/** Toast 统一管理工具。 */
object ToastUtil {
var isShow = true
private var toast: Toast? = null
fun showShort(context: Context, message: CharSequence) {
show(context, message, Toast.LENGTH_SHORT)
}
fun showShort(context: Context, message: Int) {
show(context, message.toString(), Toast.LENGTH_SHORT)
}
fun showLong(context: Context, message: CharSequence) {
show(context, message, Toast.LENGTH_LONG)
}
fun showLong(context: Context, message: Int) {
show(context, message.toString(), Toast.LENGTH_LONG)
}
fun show(context: Context, message: CharSequence, duration: Int) {
val currentToast = toast
if (currentToast == null) {
toast = Toast.makeText(context, message, duration)
} else {
currentToast.setText(message)
currentToast.duration = duration
}
toast?.show()
}
fun show(context: Context, message: Int, duration: Int) {
show(context, message.toString(), duration)
}
}