public class ToastUtil {
public static void myTosat(Context context , int imageId ,String content , int duration){
//new一个toast传入要显示的activity的上下文
Toast toast = new Toast(context);
//显示的时间
toast.setDuration(duration);
//显示的位置
toast.setGravity(Gravity.BOTTOM, 0, 300);
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageId);
//把imageView添加到toastLayout的布局当中
toastLayout.addView(imageView);
TextView textView = new TextView(context);
textView.setText(content);
// textView.setBackgroundColor(Color.GRAY);
//把textView添加到toastLayout的布局当中
toastLayout.addView(textView);
toastLayout.setBackgroundColor(Color.GRAY);
//把toastLayout添加到toast的布局当中
toast.setView(toastLayout);
toast.show();
}
public static void myTosat(Context context , int imageId ,String content , int duration){
//new一个toast传入要显示的activity的上下文
Toast toast = new Toast(context);
//显示的时间
toast.setDuration(duration);
//显示的位置
toast.setGravity(Gravity.BOTTOM, 0, 300);
//重新给toast进行布局
LinearLayout toastLayout = new LinearLayout(context);
toastLayout.setOrientation(LinearLayout.HORIZONTAL);
toastLayout.setGravity(Gravity.CENTER_VERTICAL);
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageId);
//把imageView添加到toastLayout的布局当中
toastLayout.addView(imageView);
TextView textView = new TextView(context);
textView.setText(content);
// textView.setBackgroundColor(Color.GRAY);
//把textView添加到toastLayout的布局当中
toastLayout.addView(textView);
toastLayout.setBackgroundColor(Color.GRAY);
//把toastLayout添加到toast的布局当中
toast.setView(toastLayout);
toast.show();
}
}
这个类我也是在网上看到的,但是忘记给把那位大神地址复制下来,勿怪!