Programmatically change color of shape in layer list

后端 未结 4 2124
礼貌的吻别
礼貌的吻别 2020-12-28 14:24

How can I programmatically change the color (#000000) of a shape in a layer list?

Here is my layer list:



        
4条回答
  •  感情败类
    2020-12-28 14:51

    You can also get the drawable or background of the view and set it as follows.

    LayerDrawable layerDrawable = (LayerDrawable) view.getDrawable(); //view.getBackground()
    GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable
                    .findDrawableByLayerId(R.id.layer_list_item_id);
    gradientDrawable.setColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));
    

提交回复
热议问题