// 通过LayoutInflater加载自定义布局
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast_layout, findViewById(R.id.custom_toast_layout));
// 设置布局中的元素内容
ImageView imageView = layout.findViewById(R.id.toast_icon);
imageView.setImageResource(R.drawable.ic_check_circle);
TextView text = layout.findViewById(R.id.toast_text);
text.setText("Custom Toast Message");
// 创建并显示自定义Toast
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
// 设置自定义位置
toast.setGravity(Gravity.TOP | Gravity.START, 0, 0);
toast.show();