有時(shí)候我們點(diǎn)擊一個(gè)按鈕出現(xiàn)toast但是當(dāng)不小心多次點(diǎn)擊時(shí),toast會(huì)重復(fù)出現(xiàn),這時(shí)候通過(guò)下面的ToastUtil類可以實(shí)現(xiàn)不小心多次點(diǎn)擊的問(wèn)題。
public class ToastUtil { /* private Context context; public ToastUtil(Context context) { this.context=context; }*/ private static Toast toast; public static void showToast(Context context,int code,String content) { //code=1時(shí)Toast顯示的時(shí)間長(zhǎng),code=0時(shí)顯示的時(shí)間短。 if (toast==null) { if (code ==0) toast=Toast.makeText(context,content,Toast.LENGTH_SHORT); if (code==1) toast=Toast.makeText(context,content,Toast.LENGTH_LONG); } else { toast.setText(content); } toast.show(); }}以上這篇自定義Toast工具類ToastUtil防止多次點(diǎn)擊時(shí)Toast不消失的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選