Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.widget.Toast; public class Main { /** * show short toast * * @param context : context * @param text : the msg you will show */ public static void showShortToast(Context context, String text) { showImageToast(context, 0, text, Toast.LENGTH_SHORT); } /** * show toast with image * * @param context :context * @param ImageResId :imgres id * @param text :the msg you will show * @param times :time */ @SuppressWarnings("static-access") public static void showImageToast(Context context, int ImageResId, String text, int times) { if (context == null || text == null || "".equals(text)) return; // LayoutInflater inflater = (LayoutInflater) context // .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // // View view = inflater.inflate(R.layout.dfjk_lay_custom_toast, null); // ImageView image = (ImageView) view.findViewById(R.id.dfjk_im_toast_image); // TextView textView = (TextView) view.findViewById(R.id.dfjk_tv_toast_message); // // if (0 != ImageResId) { // image.setVisibility(view.VISIBLE); // image.setImageResource(ImageResId); // } else // image.setVisibility(view.GONE); // textView.setText(text); // mHandler.removeCallbacks(run); // // if (mToast != null) { // mToast.cancel(); // mToast = new Toast(context); // mToast.setDuration(times); // mToast.setGravity(Gravity.BOTTOM, 0, 150); // mToast.setView(view); // mHandler.postDelayed(run, 500); // } else { // mToast = new Toast(context); // mToast.setDuration(times); // mToast.setGravity(Gravity.BOTTOM, 0, 150); // mToast.setView(view); // mToast.show(); // } } }