0

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?

geco17
  • 5,152
  • 3
  • 21
  • 38

2 Answers2

0

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;
geco17
  • 5,152
  • 3
  • 21
  • 38
0

Try this:

    // Call toast.xml file for toast layout

    View toastRoot = inflater.inflate(R.layout.toast, null);
    Toast toast = new Toast(context);

    // Set layout to toast 
    toast.setView(toastRoot);
    toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,
            0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();
Android Geek
  • 8,956
  • 2
  • 21
  • 35