当前位置: 移动技术网 > IT编程>移动开发>Android > 自定义Toast工具类ToastUtil防止多次点击时Toast不消失的方法

自定义Toast工具类ToastUtil防止多次点击时Toast不消失的方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

百美图小说,小米贷王哲,昌子琪

有时候我们点击一个按钮出现toast但是当不小心多次点击时,toast会重复出现,这时候通过下面的toastutil类可以实现不小心多次点击的问题。

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时toast显示的时间长,code=0时显示的时间短。
    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防止多次点击时toast不消失的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网