How to change `solid color` from the code?

前端 未结 2 1356
忘了有多久
忘了有多久 2021-01-03 16:24

I have a Shape defined in xml. Now I need to change a solid color from the code, could you please advice how?



        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-03 16:57

    I use this in my code

    GradientDrawable myGrad = (GradientDrawable)rectangle.getBackground();
    myGrad.setColor(Color.BLACK);
    

    Hope this helps :)

    EDIT: for GradientDrawable instead of ShapeDrawable

提交回复
热议问题