Toast background color being changed Toast background color being changed xml xml

Toast background color being changed


I resolved the issue. The reason for the change in the Toast background color was due to the way I was passing in the context of the View object it was contained inside.

The following line of code would cause the background color to change to the unwanted white color:

Toast.makeText(v.getContext(), "Checking login details...", Toast.LENGTH_SHORT).show();

This line of code would return the Toast to the default system style:

Toast.makeText(getApplicationContext(), "Checking login details...", Toast.LENGTH_SHORT).show();

I am not sure if there is a huge problem with fixing it like this as I am only learning. If anyone can see a problem please share. It seems to be working just fine though.


For me using getApplicationContext() wasn't an option, and for others that have this same issue, you can just set the Toast back to the default settings like so:

//Create your Toast with whatever params you needToast toast = Toast.makeText(getActivity(), "Refreshing...", Toast.LENGTH_SHORT);  //Set the background for the toast using android's default toast_frame.//Optionally you can set the background color to #646464 which is the//color of the frameView view = toast.getView();view.setBackgroundResource(android.R.drawable.toast_frame); //Get the TextView for the toast message so you can customizeTextView toastMessage = (TextView) view.findViewById(android.R.id.message); //Set background color for the text.toastMessage.setBackgroundColor((Color.parseColor("#646464"))); toast.show();


An addition to WInthrop's answer. Instead of setting the background color of the textbox as #646464, it can be set to transparent so that the toast looks like the original translucent toast

private void showToast(Context context,String msg,int duration){        Toast toast = Toast.makeText(context,msg,duration);        View view = toast.getView();        view.setBackgroundResource(android.R.drawable.toast_frame);        TextView toastMessage = (TextView) view.findViewById(android.R.id.message);        toastMessage.setBackgroundColor(Color.TRANSPARENT);        toast.show();    }