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
                }
            }
        }
    }
相关推荐
环信12 小时前
2026年开发者选择即时通讯厂商应注意的几点
前端
卷帘依旧12 小时前
Generator 全面解析 + async/await 深度对比
前端·javascript
yqcoder12 小时前
数据劫持的双雄:深入解析 Object.defineProperty 与 Proxy
开发语言·前端·javascript
lichenyang45312 小时前
鸿蒙聊天 Demo 练习 03:接入 Next.js 后端接口,实现真机前后端联调
前端
小三金12 小时前
EXPO+RN echarts图表库,以及如何使用
前端·javascript·react.js
ZFSS13 小时前
Midjourney Shorten API 的集成与使用
java·前端·数据库·人工智能·ai·midjourney·ai编程
Pu_Nine_913 小时前
IntersectionObserver 详解:封装 Vue 指令实现图片懒加载
前端·javascript·vue.js·性能优化
清灵xmf13 小时前
Web 和 Native 是怎么“对话“的?JSBridge 解答
前端·webview·native·jsbridge·hybrid
jiayong2314 小时前
前端面试题库 - ES6+新特性篇
前端·面试·es6
前端那点事14 小时前
Vue nextTick 超全解析|作用、使用场景、底层原理、Vue2/Vue3区别
前端·vue.js