Android ToastUtils,工具类。

import android.content.Context;import android.view.View;import android.widget.Toast;public class ToastUtils{    private static String oldMsg;    protected static Toast toast   = null;    private static long oneTime=0;    private static long twoTime=0;    //显示时间长    public static void showLong(Context context, String text){        show(context,text,Toast.LENGTH_LONG);    }    //显示时间短    public static void showShort(Context context, String text){        show(context,text,Toast.LENGTH_SHORT);    }    private static void show(Context mContext,String msg,int mode){        if(toast==null){            //这样的话,不管传递什么content进来,都只会引用全局唯一的Content,不会产生内存泄露            toast =Toast.makeText(mContext.getApplicationContext(), msg, Toast.LENGTH_SHORT);            toast.show();            oneTime=System.currentTimeMillis();        }else{            twoTime=System.currentTimeMillis();            if(msg.equals(oldMsg)){                if(twoTime-oneTime>mode){                    toast.show();                }            }else{                oldMsg = msg;                toast.setText(msg);                toast.show();            }        }        oneTime=twoTime;    }    }


更多相关文章

  1. android中的全局变量定义与使用
  2. Android定义的路径全局变量
  3. android全局Toast
  4. Android获得全局进程信息以及进程使用的内存情况
  5. Android用Application设置全局变量以及使用
  6. Android 扫码盒子全局接收付款码(全局事件&上层接收&多重下发)
  7. Android-AlarmManager(全局定时器/闹钟)
  8. Android 全局Activity动画设置
  9. android 上 webkit js 扩展之全局本地对象实现步骤

随机推荐

  1. android 拍照 Camera类 使用照相机进行拍
  2. travis-ci如何配置android
  3. Android(安卓)屏幕滑动事件
  4. Android(安卓)listview分割线的颜色设置
  5. android service 实例
  6. Android的NDK开发(5)————Android(安
  7. android仿ios弹性页
  8. Android利用tcpdump抓包
  9. 操作 Calendar事件
  10. android 编译内核