Android实用工具类 CustomToast

自定义CustomToast

防止 Toaster 的重复弹出,简单实用

package com.li.handledata.util;

import android.content.Context;
import android.widget.Toast;

public class CustomToast {

    private static Toast mToast;

    public static void showToast(Context mContext, String text, int duration) {
        if (mToast != null) {
            mToast.setText(text);
        } else {
            mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public static void showToast(Context mContext, int resId, int duration) {
        showToast(mContext, mContext.getResources().getString(resId), duration);
    }
}

猜你喜欢

转载自blog.csdn.net/su749520/article/details/81263100