First add the id for the item. Find the item by ID and change the color.
<item android:id="@+id/shape_1" android:drawable="@color/gray_background"/>
<item android:id="@+id/shape_2"
android:drawable="@color/light_green"
android:bottom="@dimen/event_button_bottom_color"/>
Change at runtime:
LayerDrawable layerDrawable = (LayerDrawable) getResources()
.getDrawable(R.drawable.my_drawable);
GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable
.findDrawableByLayerId(R.id.shape_1);
gradientDrawable.setColor(...);
source
share