有时候我们需要使用Toast显示信息,快了之后似乎不能及时显示我们想要弹出的信息, 因为Toast的显示是压栈的. 如果使用单例可解决这一问题.上代码, 很简单.

 1 package com.fyc.util;
 2 
 3 import android.content.Context;
 4 import android.widget.Toast;
 5 
 6 public class ToastUtils {
 7 
 8     private static Toast mToast;
 9     
10     public static void show(Context ctx, String text) {
11         if (mToast == null) {
12             mToast = Toast.makeText(ctx, text, Toast.LENGTH_SHORT);
13         } else {
14             mToast.setText(text);
15         }
16         mToast.show();
17     }
18 }

如果是自定的布局也是一样.  

相关文章:

  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2021-12-11
  • 2022-12-23
猜你喜欢
  • 2021-10-06
  • 2021-05-09
  • 2021-09-18
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
相关资源
相似解决方案