I have
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#FFFF00" />
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
</shape>
<TextView
android:background="@drawable/test"
android:layout_height="45dp"
android:layout_width="100dp"
android:text="Moderate"
/>
So now I want this shape to change colors based on information I get back from a web service call. So it could be maybe yellow or green or red or whatever depending on the color I receive from the web serivce call.
How can I change the color of the shape? Based on this information?
View.getBackground()
returns aGradientDrawable
and not aShapeDrawable
causing the app to crash at runtime, due to invalid cast when trying to get the reference and set the color programmatically. [Android Shape doc]( developer.android.com/guide/topics/resources/…) states: COMPILED RESOURCE DATATYPE: Resource pointer to aGradientDrawable
. – Trakas