Setting background color on toast makes it rectangular

前端 未结 2 744
闹比i
闹比i 2021-01-18 18:45

If I set the background color of my Toast with

            t.getView().setBackgroundColor(
                    ctx.getResources().getColor(R.co         


        
相关标签:
2条回答
  • 2021-01-18 19:21

    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);
    
    0 讨论(0)
  • 2021-01-18 19:27

    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.

    0 讨论(0)
提交回复
热议问题