package com.emato.ich.utils; import android.content.Context; import android.os.Handler; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import android.widget.Toast; import com.emato.ich.R; /** * 弹出框工具类 */ public class ToastUtils { private static Toast mToast; private static Handler mHandler = new Handler(); // private static Runnable runnable = new Runnable() { // public void run() { // mToast.cancel(); // //toast隐藏后,将其置为null // mToast=null; // } // }; /** * 弹出框 * @param context 程序上下文 * @param msg 弹出信息 */ public static void make(Context context, String msg) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); //自定义布局 View view = inflater.inflate(R.layout.custom_toast, null); TextView text = (TextView) view.findViewById(R.id.toast_message); //显示的提示文字 text.setText(msg); // mHandler.removeCallbacks(runnable); if (mToast != null) { mToast.cancel(); } mToast = new Toast(context); mToast.setDuration(Toast.LENGTH_SHORT); mToast.setGravity(Gravity.CENTER, 0, -22); mToast.setView(view); mToast.show(); // mHandler.removeCallbacks(runnable); } }