views:

43

answers:

1

I'm trying to change the color of a horizontal progress bar (foreground). I came across this example and am trying to model my XML file off it. However, I get a compiler error at the following statement:

myProgressBar.setProgressDrawable(R.drawable.progress_horizontal);

The error is "The method setProgressDrawable(Drawable) in the type ProgressBar is not applicable for the arguments (int)."

I believe the reason is inside the R.java file I see the following line:

public static final int progress_horizontal=0x7f02002f;

So, do I define this XML file as a drawable and not an integer, or is there another way to solve this?

Thanks.

Edit: Including XML file

<item android:id="@android:id/background">
    <shape>
        <corners android:radius="5dip" />
        <gradient
                android:startColor="#ff9d9e9d"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#80ffd300"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#ffffd300"
                    android:centerColor="#ffffb600"
                    android:centerY="0.75"
                    android:endColor="#ffffcb00"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>

+1  A: 

The R class is generated by Android compiler, all fields of the inner class in R.java refer to the resources in res folder by android:id xml attribute. The Resouce class can retrieve the resource object by using the resource id. So, you can get Drawable object through Resource.getDrawable(int).

Tony
Cool, that compiled properly. Now I just have to figure out how to use the XML file properly. Thanks.