Setting background color on toast makes it rectangular

前端 未结 2 743
闹比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);
    

提交回复
热议问题