上一篇文章主要分享了Android 开发中自定义Toast-CSDN博客 这篇文章主要分享另一种写法也可以实现自定义布局+设置不同的时长:
自定义吐司的类: public class CustomToast extends Toast {private static int mduration;public CustomToast(Context context) {super(context);}public static CustomToast makeText(Context context, CharSequence text, int duration,String content) {LayoutInflater inflater = LayoutInflater.from(context);View customToastView = inflater.inflate(R.layout.custom_toast, null);TextView toastTextView = customToastView.findViewById(R.id.toast_text);mduration = duration;if (content.contentEquals("3")){toastTextView.setBackgroundResource(R.drawable.orange_bg18);toastTextView.setText(text); // toastTextViewnt.setText("报告可能生成失败,请稍后前往报告列表查看&#