Toast.makeText(context, str,
Toast.LENGTH_SHORT).show();
}
Toast toast = Toast.makeText(context,
"带图片的Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
ImageView imageCodeProject = imageCodeProject.setImageResource(imgId);
toastView.addView(imageCodeProject, 0);
toast.show();
}
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(custom,
(ViewGroup) findViewById(R.id.llToast));
ImageView image = (ImageView) layout
.findViewById(tvImageToast);
image.setImageResource(icon);
TextView title = (TextView) layout.findViewById(tvTitleToast);
title.setText("Attention");
TextView text = (TextView) layout.findViewById(tvTextToast);
text.setText("完全自定义Toast");
Toast toast = toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}