Is there any way to change contents of shape.xml of drawable folder?

18 views
Skip to first unread message

Raj

unread,
Sep 8, 2011, 10:33:38 AM9/8/11
to android-...@googlegroups.com
Hello,
In app, I've used a shape.xml for giving a rounded rectangle shape to my view (as seen below) and in that, I've used some color. Now, what I want to do is change the color in this shape.xml dynamically so that I can make some fade color animation out of it. So is there any way to change the color value in that file dynamically? Here is that file -

<?xml version="1.0" encoding="utf-8"?>
    android:shape="rectangle">
    <corners
        android:radius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp" />
    <size
        android:width="65dp"
        android:height="65dp" />
    <solid
        android:color="#FFA500" />
</shape>

Alternatively, can you suggest some dynamic code from which I can achieve the same that this shape.xml does, so that I can pass a color as a parameter over there?

Please Help.

-Regards,
Rajkiran Bande.

Kosmos Grillis

unread,
Sep 8, 2011, 12:58:27 PM9/8/11
to android-...@googlegroups.com

What will trigger the dynamic color change; you should probably merely change the color alpha property in your code, if the color must be predefined, you could/should define a color resource for the shape, adjust the color resource  alpha according to you're desired animation time while associating it with the shape - have a look at the Animation object.

On 09/09/2011 1:05 AM, "Raj" <bande.r...@gmail.com> wrote:
> Hello,
> In app, I've used a shape.xml for giving a rounded rectangle shape to my
> view (as seen below) and in that, I've used some color. Now, what I want to
> do is change the color in this shape.xml dynamically so that I can make some
> fade color animation out of it. So is there any way to change the color
> value in that file dynamically? Here is that file -
>
> *<?xml version="1.0" encoding="utf-8"?>*
> *<shape xmlns:android="http://schemas.android.com/apk/res/android"*
> * android:shape="rectangle">*
> * <corners*
> * android:radius="10dp"*
> * android:topLeftRadius="10dp"*
> * android:topRightRadius="10dp"*
> * android:bottomLeftRadius="10dp"*
> * android:bottomRightRadius="10dp" />*
> * <size*
> * android:width="65dp"*
> * android:height="65dp" />*
> * <solid*
> * android:color="#FFA500" />*
> *</shape>
>
> *Alternatively, can you suggest some dynamic code from which I can achieve
> the same that this shape.xml does, so that I can pass a color as a parameter
> over there?
> *
> Please Help.*
> *
> *
> *-Regards,*
> *Rajkiran Bande.*
>
> --
> You received this message because you are subscribed to the Google Groups "android-platform" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/rCt7jgiIcXIJ.
> To post to this group, send email to android-...@googlegroups.com.
> To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
>
Reply all
Reply to author
Forward
0 new messages