自定义Toast
1 package com.hixin.appexplorer; 2 3 import android.content.Context; 4 import android.graphics.Color; 5 import android.view.Gravity; 6 import android.widget.ImageView; 7 import android.widget.LinearLayout; 8 import android.widget.TextView; 9 import android.widget.Toast; 10 11 public class MyToast { 12 13 public static void myToastShow(Context context,int imageResId, String content, int duration) { 14 Toast toast = new Toast(context); 15 toast.setDuration(duration); 16 toast.setGravity(Gravity.BOTTOM, 0, 25); 17 18 LinearLayout toastLayout = new LinearLayout(context); 19 toastLayout.setOrientation(LinearLayout.HORIZONTAL); 20 toastLayout.setGravity(Gravity.CENTER_VERTICAL); 21 22 ImageView imageView = new ImageView(context); 23 imageView.setImageResource(imageResId); 24 25 toastLayout.addView(imageView); 26 27 TextView tv_content = new TextView(context); 28 tv_content.setText(content); 29 tv_content.setBackgroundColor(Color.BLACK); 30 31 toastLayout.addView(tv_content); 32 33 toast.setView(toastLayout); 34 toast.show(); 35 36 } 37 }