Hello,
Welcome to our Microsoft Q&A platform!
The values I will be using for the colors are color resources. How can I edit the GradientDrawable(s)
Try to get the LayerDrawable
object from the view's background in code, then you could get the GradientDrawable
via the LayerDrawable.GetDrawable()
command. In GradientDrawable class, it provides SetColors
method to set the colors.
Here is the related code, you could refer to it.
var layout = FindViewById<LinearLayout>(Resource.Id.layout);
var drawable = layout.Background as LayerDrawable;
var count = drawable.NumberOfLayers;//you could traverse the drawables to reset the colors
//change the colors of the first drawable
var item1 = drawable.GetDrawable(0) as GradientDrawable;
item1.SetColors(new int[] { Color.Blue, Color.Green, Color.Blue });
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.