Search code examples
javaandroidandroid-xmltoastandroid-toast

Apply default Toast style to custom Toast


I need to apply the default toast style to a custom toast message I've made. I made a message that shows upside down, like so:

Toast t = new Toast(activity);
TextView text = new TextView(activity);
text.setText(msg);
text.setRotation(180);
t.setView(text);
t.setDuration(length);

It works fine but I'm not sure how to go about setting my custom text to have the same "look and feel" as the original. Some sources suggest using a custom toast.xml (see here) and setting the layout/view but I would like to take android's default. Can anyone point me in the right direction?


Solution

  • It was really simple, I solved it.

    Creating the Toast as normal with Toast.makeText(activity, message, length) I just grabbed the view, rotated it and reset it.

    Toast toast = Toast.makeText(activity, msg, length);
    View view = toast.getView();
    view.setRotation(180);
    toast.setView(view);
    
    return toast;