I have a drawable that I use as the background for LinearLayout. I would like to change the color of this shape at runtime. I tried using several methods .. but no one works.
I followed the approach described here: http://www.anddev.org/android-2d-3d-graphics-opengl-problems-f55/change-shape-drawable-solid-color-t16798.html
But you have the same problem ... this is not a failure .. but the color does not change!
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#00A6C1" /> <corners android:radius="@dimen/square_corners" /> </shape>
Code snippet:
GradientDrawable drawable = (GradientDrawable) activity.getResources().getDrawable(R.drawable.blue_square_shape); int color = ((Application) getApplication()).getColor(); drawable.setColor(color); block.findViewById(R.id.blockSquare).setBackgroundDrawable(drawable); findViewById(R.id.blockSquare).postInvalidate();
Any clue? I went all day searching the Internet ... and it gets very annoying ...
UPDATE:
When I try to do the same with this form:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/shape" android:shape="rectangle"> <gradient android:startColor="#1FBCCF" android:endColor="#06A4C1" android:angle="270" /> <corners android:topLeftRadius="@dimen/footer_corners" android:topRightRadius="@dimen/footer_corners" /> </shape>
The color turns black ... that I think it can be changed ...
android drawable
neteinstein May 09 '11 at 18:20 2011-05-09 18:20
source share