5

If I set the background color of my Toast with

            t.getView().setBackgroundColor(
                    ctx.getResources().getColor(R.color.myorange));

the new (Android 4.4) rounded Toast becomes rectangular. Any way to prevent this apart from using a custom rounded background Drawable?

enter image description here

enter image description here

fweigl
  • 21,278
  • 20
  • 114
  • 205

2 Answers2

4

Do not try to set the background color directly, set a color filter instead. That will preserve the toast shape:

int backgroundColor = ResourcesCompat.getColor(t.getView().getResources(), R.color.myorange, null);
t.getView().getBackground().setColorFilter(backgroundColor, PorterDuff.Mode.SRC_IN);
Thomas Hetzer
  • 1,537
  • 13
  • 24
1

There is no way to prevent that. The default background for the toast is a drawable that defines the rounded corners. If you want rounded corners in a different color, you'll have to define your own shape drawable.

dm78
  • 1,570
  • 1
  • 16
  • 28