12345678910111213141516171819202122232425262728293031323334353637383940 |
- 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;
- }
- };
- 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);
- mToast = new Toast(context);
- mToast.setDuration(Toast.LENGTH_SHORT);
- mToast.setGravity(Gravity.CENTER, 0, -22);
- mToast.setView(view);
- mToast.show();
- }
- }
|