zoukankan      html  css  js  c++  java
  • ToastUtils

    public class ToastUtils {
    
        private static String TAG="ToastUtils";
        private static Toast toast;
    
        /**
         *单例获取实例
         * @param context
         * @return
         */
    
        private static ToastUtils toastUtils;
        private  ToastUtils(Context context){
            toast=Toast.makeText(context.getApplicationContext(),null,Toast.LENGTH_SHORT);
        }
        public static ToastUtils instance(Context context){
    
            if(toastUtils==null){
                synchronized (ToastUtils.class){
                    if(toastUtils==null){
                        toastUtils=new ToastUtils(context);
                    }
                }
            }
            return toastUtils;
        }
    
        //短时间显示Toast
        public void showShortToast(String msg){
            toast.setText(msg);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.show();
        }
    
        //短时间显示Toast
        public void showShortToast(int resId){
            toast.setText(resId);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.show();
        }
    
        //长时间显示Toast
        public void ShowLongToast(String msg){
            toast.setText(msg);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.show();
        }
        //长时间显示Toast 
        public void ShowLongToast(int resId){
            toast.setText(resId);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.show();
        }
    
        //取消toast
        public void cancleToast(){
            if(toast!=null){
                toast.cancel();
                toast=null;
            }
            toastUtils=null;
        }
    
    }
    

      

  • 相关阅读:
    ui、li模拟下拉框
    六项精进
    Echarts柱状图添加点击事件
    [UWP]爱恋动漫BT开发小记
    [杂谈]这个四月
    [uwp]自定义图形裁切控件
    [uwp]自定义Behavior之随意拖动
    [uwp]数据绑定再学习
    [mvc]记一次“项目”的历程
    [uwp]ImageSource和byte[]相互转换
  • 原文地址:https://www.cnblogs.com/wangjiaghe/p/7815455.html
Copyright © 2011-2022 走看看