更新时间:2021-07-30 09:14:21
改变你的方法
从
showToastMessage(String message)
到
showToastMessage(Context context,String message);
似乎方面的问题我
it seems context problem to me
你的函数看起来像这样
public static void showToastMessage(Context context,String message){
LayoutInflater inflater = context.getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) ((Activity) context).findViewById(R.id.customToast));
// set a message
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(message);
// Toast...
Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}