Android 自定义Toast

来源:互联网 发布:微领袖商学院源码 编辑:程序博客网 时间:2024/06/10 04:43
public class MyToast {    //传过来的参数,MyToast.showMyToast(this, R.drawable.notification, "杀死了"+count+"个进程");    public static void  showMyToast(Context context, int icon , String text){        Toast toast = new Toast(context);        View view = View.inflate(context, R.layout.mytoast, null);        TextView tv_toast = (TextView) view.findViewById(R.id.tv_toast);        ImageView iv_toast = (ImageView) view.findViewById(R.id.iv_toast);        tv_toast.setText(text);        iv_toast.setImageResource(icon);        toast.setView(view);        toast.setDuration(Toast.LENGTH_SHORT);        toast.show();    }}
0 0