Reputation: 710
How do I change the background color of a custom shape like this:
<?xml version="1.0" encoding="UTF-8"?>
<inset android:insetLeft="1.0px" android:insetRight="1.0px" android:insetTop="0.0px" android:insetBottom="1.0px" xmlns:android="http://schemas.android.com/apk/res/android">
<selector>
<item>
<shape>
<stroke android:width="1.0px" android:startColor="@color/grey_rounded_container_slider_start" android:endColor="@color/grey_rounded_container_slider_end" />
<gradient android:startColor="@color/grey_rounded_container_slider_start" android:endColor="@color/grey_rounded_container_slider_end" android:angle="270.0" />
<corners android:radius="10.0dip" />
</shape>
</item>
</selector>
</inset>
programmatically? I would only need to change the gradient(background color). So I assume I need to give the gradient an id? And then how should I use view.findViewById(R.id.name) to change my gradient color? Thanks.
Upvotes: 0
Views: 1095
Reputation: 15515
You can't change the color of drawable programmatically. Alternatively You can have more than one shape, And change the drawable file programmatically.
You can use following code snippet for change programmatically.
if(true)
yourview.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape1))
else
yourview.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape2))
I hope this will help you.
Upvotes: 1