Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting background color on toast makes it rectangular

Tags:

android

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

like image 601
fweigl Avatar asked Jan 08 '14 14:01

fweigl


People also ask

How do I change the background color of my toast?

If you need to change the background of the Toast then you need to use getView(). setBackground() function. If You need to change the color of the view created then you need to use getView(). getBackground().

How do you make colored toast?

Use a small paint brush and dip the brush into the food coloring. Then take a piece of bread and paint a face or picture of choice on it. Place the bread into a toaster and wait till the bread is lightly toasted. Butter lightly to give taste.


1 Answers

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);
like image 58
Thomas Hetzer Avatar answered Oct 12 '22 19:10

Thomas Hetzer