我正在尝试制作自定义吐司,但收到以下错误:
找不到符号 (ViewGroup) findViewById(R.id.toast_root));
同时findViewById()
可以在其他代码行中看到。我的错误是什么?
public class MyCustomToast extends Toast {
public MyCustomToast(Context context){
super(context);
}
public static Toast customToast(Context context, CharSequence text, int duration) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_root));
ImageView image = (ImageView) layout.findViewById(R.id.toast_image);
image.setImageResource(R.drawable.skipper_toast);
TextView text_toast = (TextView) layout.findViewById(R.id.toast_text);
text_toast.setText(text);
Toast toast = new Toast(context);
toast.setGravity(Gravity.TOP, 0, 0);
toast.setDuration(duration);
toast.setView(layout);
toast.show();
return toast;
}
}