On Aug 23, 2011, at 3:50 PM, chobo2 wrote:
> I want to change the color of a shape dynamically but I am unsure how.
> 
> <?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>
...
> // this seems to be how do it in android
> ShapeDrawable bgShape = (ShapeDrawable )btn.getBackground();
> bgShape.getPaint().setColor(Color.BLACK);
...
>    ShapeDrawable bgShape = (ShapeDrawable)
> Resources.GetDrawable(Resource.Drawable.danger_box);
> 
> but it crashes on the first line(does not really seem to give a error).

It crashes because of an InvalidCastException: Resources.GetDrawable() is 
returning an Android.Graphics.Drawables.GradientDrawable, not a ShapeDrawable.

I'm not sure how the Android/Java code works at all (assuming it does; I 
haven't tested), as the Android documentation clearly states that the <shape/> 
element will return a GradientDrawable:

        
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

        compiled resource datatype: Resource pointer to a GradientDrawable.

 - Jon

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to