package it.domain;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
//自定义toast
public class MyToast {
public static void MyToastShow(Context context, int resid,
String text, int duration) {
Toast mytoast=new Toast(context);//获得一个toast
//设置toast的布局
LinearLayout toastlayout=new LinearLayout(context);
//设置toast的显示方向
toastlayout.setOrientation(LinearLayout.HORIZONTAL);
//new一个要放进布局的图片容器
ImageView iv=new ImageView(context);
iv.setImageResource(resid);
//new一个要放进布局的text
TextView tv=new TextView(context);
//设置TextView的内容
tv.setText(text);
//添加一个图片控件
toastlayout.addView(iv);
//添加文本控件
toastlayout.addView(tv);
//将tast的布局设置成我们已经定义好的toastlayout
mytoast.setView(toastlayout);
//显示mytoast
mytoast.show();
}
}
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
//自定义toast
public class MyToast {
public static void MyToastShow(Context context, int resid,
String text, int duration) {
Toast mytoast=new Toast(context);//获得一个toast
//设置toast的布局
LinearLayout toastlayout=new LinearLayout(context);
//设置toast的显示方向
toastlayout.setOrientation(LinearLayout.HORIZONTAL);
//new一个要放进布局的图片容器
ImageView iv=new ImageView(context);
iv.setImageResource(resid);
//new一个要放进布局的text
TextView tv=new TextView(context);
//设置TextView的内容
tv.setText(text);
//添加一个图片控件
toastlayout.addView(iv);
//添加文本控件
toastlayout.addView(tv);
//将tast的布局设置成我们已经定义好的toastlayout
mytoast.setView(toastlayout);
//显示mytoast
mytoast.show();
}
}