Reputation: 386
I have a button with the following background :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"><shape android:shape="oval">
<gradient android:centerX="50%" android:centerY="50%" android:endColor="#d91d1d" android:gradientRadius="20" android:startColor="#8c3131" android:type="radial" />
<corners android:radius="5dp" />
<stroke android:width="1.75dp" android:color="#DF1B1D" />
<padding android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="1dp" />
</shape></item>
<item><shape android:shape="oval">
<gradient android:centerX="50%" android:centerY="50%" android:endColor="#d91d1d" android:gradientRadius="20" android:startColor="#8c3131" android:type="radial" />
<corners android:radius="5dp" />
<stroke android:width="1.10dp" android:color="#FFFFFF" />
<padding android:bottom="2dp" android:left="4dp" android:right="4dp" android:top="1dp" />
</shape></item>
And I need to edit in the code the gradient colors, and the stroke color (not the same color for both). (I have ~20 states possible) Can't find how to edit my button's stroke color or gradient color.
Thank's
Upvotes: 1
Views: 1173
Reputation: 54682
You cannot edit the resource file from code. So if you want to change the drawable from code then don't use a fixed drawable xml. Use GradientDrawable instead to create the drawable from code.
Upvotes: 1