最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Toast類避免顯示時間疊加的方法

 更新時間:2018年08月28日 10:53:13   作者:琦琦安卓進階  
這篇文章主要為大家詳細(xì)介紹了Toast類避免顯示時間疊加的方法,線程中可用,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文為大家分享了Toast類避免顯示時間疊加的方法,供大家參考,具體內(nèi)容如下

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.widget.Toast;
 
/**
 * Toast工具類
 * Created by user on 2016/12/22.
 */
 
public class ToastUtil {
 
  private static Toast toast = null;
  private static ToastUtil toastUtil = null;
 
  public ToastUtil(){}
 
  public synchronized static ToastUtil getInstance(){
    if(null == toastUtil){
      toastUtil = new ToastUtil();
    }
 
    return toastUtil;
  }
 
  public void showToast(Context context, String string){
 
    if(toast != null){
      toast.cancel();
    }
      toast = Toast.makeText(context, string,Toast.LENGTH_SHORT);
      toast.show();
  }
 
  public void showToast(Fragment fragment, String string){
    showToast(fragment.getActivity(),string);
  }
 
  public void showToast(Activity activity, String string){
    if(toast != null){
      toast.cancel();
    }
    toast = Toast.makeText(activity, string,Toast.LENGTH_SHORT);
    toast.show();
  }
 
  public void showToastTest(Context context){
    if(toast != null){
      toast.cancel();
    }
    toast = Toast.makeText(context, "click",Toast.LENGTH_SHORT);
    toast.show();
  }
 
  public void showToastTest(Fragment fragment){
    showToastTest(fragment.getActivity());
  }
 
  public void showToastTest(Activity activity){
    if(toast != null){
      toast.cancel();
    }
    toast = Toast.makeText(activity, "click",Toast.LENGTH_SHORT);
    toast.show();
  }
}
 
    if(null == toastUtil){
      toastUtil = new ToastUtil();
    }
 
    return toastUtil;
  }
public void showToastInThread(Context context,String msg){
    Looper.prepare();
    if(toast != null){
      toast.cancel();
    }
    toast = Toast.makeText(context,msg,Toast.LENGTH_SHORT);
    toast.show();
    Looper.loop();
  }
  public void showToast(Context context, String string){
 
    if(toast != null){
      toast.cancel();
    }
      toast = Toast.makeText(context, string,Toast.LENGTH_SHORT);
      toast.show();
  }
 
}

這是一個封裝好的Toast工具類,避免時間疊加

使用方法

ToastUtil.getInstance().showToast(mContext,"test");

如果在線程中執(zhí)行的話,必須按照如下格式

ToastUtil.getInstance().showToastInThread(mContext,"str");

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

淳安县| 大宁县| 庆元县| 沭阳县| 五指山市| 瑞丽市| 新昌县| 页游| 利津县| 宁海县| 邵阳市| 淳安县| 乌拉特中旗| 来安县| 清远市| 祁门县| 鄂伦春自治旗| 榆社县| 黄大仙区| 垦利县| 灌云县| 广汉市| 常熟市| 华容县| 浪卡子县| 玉山县| 牙克石市| 镇江市| 新巴尔虎左旗| 驻马店市| 玉田县| 朝阳区| 徐闻县| 昌黎县| 南陵县| 扶绥县| 密云县| 丽江市| 体育| 东至县| 射阳县|