我正在创建一条祝wine 词.当您输入错误的信息时,这个祝wine 词就会出现,但当我快速输入并再次输入正确的数据时,祝wine 词消息会继续出现在新页面上.
我不想写LENGTH_SHORT,因为男人需要能够轻松地阅读消息
我为它写了一个扩展,但它对我不起作用
private fun Context.toastCreate(): Toast {
return Toast(this)
}
fun Context.showError(message: String) {
val inflater = LayoutInflater.from(this)
val layout: View = inflater.inflate(R.layout.custom_toast_layout, null)
val text = layout.findViewById<TextView>(R.id.text)
text.text = message
val toast = toastCreate()
toast.duration = Toast.LENGTH_LONG
toast.view = layout
toast.show()
}
fun Context.cancelError() {
this.toastCreate().cancel()
}