服了,Toast都被Rom影响了
由于开发过程中,使用Toast时,总是看到消息的前面加上了app_name:消息,刚开始还以为是程序本来如此,后来才发现,有可能是手机Rom的问题。
通过以下的操作,就能覆盖Rom定制过的影响。
scss
val toast = Toast.makeText(context, text, Toast.LENGTH_SHORT)
toast.setText(text)
toast.show()
scss
fun showText(context: Context, text: String) {
if (text.isEmpty()) {
return
}
if (oldMsg.isEmpty()) {
val toast = Toast.makeText(context, text, Toast.LENGTH_SHORT)
toast.setText(text)
toast.show()
oldMsg = text
oneTime = System.currentTimeMillis()
} else {
twoTime = System.currentTimeMillis()
if (twoTime - oneTime > 2000) {
val toast = Toast.makeText(
context,
text,
Toast.LENGTH_SHORT
)
toast.setText(text)
toast.show()
oneTime = twoTime
oldMsg = text
} else {
if (oldMsg != text) {
val toast = Toast.makeText(
context,
text,
Toast.LENGTH_SHORT
)
toast.setText(text)
toast.show()
oneTime = twoTime
}
}
}
}