Android Toast消息受到Rom的影响

服了,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
                }
            }
        }
    }
相关推荐
焰火19996 分钟前
[Vue]可重置的响应式状态reactive
前端·vue.js
陆枫Larry7 分钟前
CSS transform scale:图片放大效果背后的原理
前端
老王以为17 分钟前
为什么 React 和 Vue 不一样?
前端·vue.js·react.js
web打印社区19 分钟前
2026最新Web静默打印解决方案,无插件无预览,完美替代Lodop
前端·javascript·vue.js·electron·pdf
这个DBA有点耶34 分钟前
分组排名不用窗口函数?那你还在写几十行的子查询
前端·代码规范
ZhiqianXia37 分钟前
《The Design of Design》阅读笔记
前端·笔记·microsoft
有马贵将1 小时前
【5】微前端知识点总结
前端·架构
mkae1 小时前
eBPF高性能版fail2ban
前端
_柴富自由1 小时前
前端项目国际化解决方案
前端
isixe1 小时前
Uniapp 监听回到前台并全局唯一弹窗
前端