Blankj / AndroidUtilCode

:fire: Android developers should collect the following utils(updating).
https://blankj.com/2016/07/31/android-utils-code/
Apache License 2.0
33.32k stars 10.69k forks source link

Toast弹不出来 #652

Closed lks6123 closed 6 years ago

lks6123 commented 6 years ago

最新1.20.3 版, ToastUtils 在部分小米手机上弹不出来Toast,例如 红米 Note 4x

Blankj commented 6 years ago

前两天也有人反应这个问题,我手头没相关机器,你有空的话帮我打断点调试下吧,主要是 ToastUtils 下面这段代码,看看 identifier 有没有找到,我觉得是这个问题

private static Toast makeNormalToast(Context context, CharSequence text, int duration) {
    if ("Xiaomi".equals(Build.MANUFACTURER)) {
        Toast toast = new Toast(context);
        int identifier = Resources.getSystem()
                .getIdentifier("transient_notification", "layout", "android");
        View view = getView(identifier);
        toast.setView(view);
        toast.setDuration(duration);
        TextView tv = view.findViewById(android.R.id.message);
        tv.setText(text);
        return toast;
    }
    return Toast.makeText(context, text, duration);
}
Blankj commented 6 years ago

试试 1.20.4 版本,已经解决了