且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在所有屏幕自定义敬酒的消息?

更新时间: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();
           }