博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小米手机Toast显示带应用名称问题解决方法
阅读量:7090 次
发布时间:2019-06-28

本文共 3417 字,大约阅读时间需要 11 分钟。

近期为了适配刘海屏,向公司申购了一步小米8的手机,然后测试人员那边测出来一堆适配的问题,其中有一个每一个Toast会显示app的名称+显示的内容,然后网上查找了一下解决方法记录一下,顺便封装了ToastUtil方便调用。

1 package cc.wulian.smarthomev6.support.utils;  2   3 import android.support.annotation.StringRes;  4 import android.view.Gravity;  5 import android.widget.TextView;  6 import android.widget.Toast;  7   8 import cc.wulian.smarthomev6.R;  9 import cc.wulian.smarthomev6.main.application.MainApplication; 10  11 /** 12  * Created by huxc on 2017/6/15. 13  * 统一弹Toast 14  */ 15  16 public class ToastUtil { 17     private static Toast toast; 18  19     public static void show(String text) { 20         if (toast == null) { 21             toast = Toast.makeText(MainApplication.getApplication(), null, Toast.LENGTH_SHORT);           //这个地方第二个参数需要为null 22             toast.setText(text); 23         } else { 24             toast.setText(text); 25         } 26         toast.show(); 27     } 28  29     public static void show(@StringRes int resId) { 30         if (toast == null) { 31             toast = Toast.makeText(MainApplication.getApplication(), null, Toast.LENGTH_SHORT); 32             toast.setText(resId); 33         } else { 34             toast.setText(resId); 35         } 36         toast.show(); 37     } 38  39     /** 40      * 弹出多个toast时, 不会一个一个的弹, 后面一个要显示的内容直接显示在当前的toast上 41      */ 42     public static void single(String msg) { 43         if (toast == null) { 44             toast = Toast.makeText(MainApplication.getApplication(), null, Toast.LENGTH_SHORT); 45             toast.setText(msg); 46         } else { 47             toast.setText(msg); 48         } 49         toast.show(); 50     } 51  52     public static void singleLong(String msg) { 53         if (toast == null) { 54             toast = Toast.makeText(MainApplication.getApplication(), null, Toast.LENGTH_LONG); 55             toast.setText(msg); 56         } else { 57             toast.setText(msg); 58         } 59         toast.show(); 60     } 61  62     /** 63      * 多行居中显示 64      */ 65     public static void singleCenter(@StringRes int msg) { 66         if (toast == null) { 67             toast = Toast.makeText(MainApplication.getApplication(), null, Toast.LENGTH_SHORT); 68             toast.setText(msg); 69         } else { 70             toast.setText(msg); 71         } 72         ((TextView) toast.getView().findViewById(android.R.id.message)).setGravity(Gravity.CENTER); 73         toast.show(); 74     } 75  76     /** 77      * 多行居中显示 78      */ 79     public static void singleCenter(String msg) { 80         if (toast == null) { 81             toast = Toast.makeText(MainApplication.getApplication(), null, Toast.LENGTH_SHORT); 82             toast.setText(msg); 83         } else { 84             toast.setText(msg); 85         } 86         ((TextView) toast.getView().findViewById(android.R.id.message)).setGravity(Gravity.CENTER); 87         toast.show(); 88     } 89  90     /** 91      * 弹出多个toast时, 不会一个一个的弹, 后面一个要显示的内容直接显示在当前的toast上 92      */ 93     public static void single(@StringRes int msg) { 94         if (toast == null) { 95             toast = Toast.makeText(MainApplication.getApplication(), null, Toast.LENGTH_SHORT); 96             toast.setText(msg); 97         } else { 98             toast.setText(msg); 99         }100         toast.show();101     }102 }

Toast.makeText()方法的第二个参数传null,然后mtoast.settext(text)重新设置一下

转载于:https://www.cnblogs.com/hxchaoshuai/p/9987315.html

你可能感兴趣的文章
大数据时代怎么做
查看>>
java基本语法
查看>>
细说HTTP之上篇
查看>>
将Eclipse Maven项目 导入 IDEA 步骤 成功运行 已测试!~LC
查看>>
Exchange Server 2010的俩种版本比较
查看>>
asp.net 插入视频
查看>>
laravel中的表单请求类型和CSRF防护(六)
查看>>
有1000瓶水,其中有一瓶有毒,小白鼠只要尝一点带毒的水24小时后就会死亡,至少要多...
查看>>
我的友情链接
查看>>
监控指定文件所有机器的网络状况
查看>>
11、网络--Linux Bridge(网桥基础)
查看>>
监控apache脚本原理
查看>>
参观迅达云成观后感
查看>>
linux(ubuntu)查看硬件设备命令
查看>>
centos 上 GraphicsMagic安装笔记
查看>>
tomcat与resin
查看>>
android应用要搞起了
查看>>
一个简单的css3 动画例子
查看>>
Facebook ATC 弱网测试项目部署
查看>>
关于p-vol和s-vol
查看>>