Resources Return Drawable Wrong Type

I have an application with three ProgressBars , each of which has its own Drawable progress. These Drawables are pretty simple: each one has a LayerDrawable with a transparent background layer, a transparent secondary level of progress, and a solid level of color progress.

All three ProgressBars displayed in one layout.

The problem that I started working with is that one of these ProgressBars does not display correctly - it just does not show any progress. This only happens on some devices (confirmed on an emulated Nexus One running 2.3.3 and Galaxy SII running 4.1.2).

I set a breakpoint in onCreate and found that the first two ProgressBars have the mProgressDrawable property mProgressDrawable correctly to LayerDrawable , and the third to ColorDrawable .

Of course, the following code returns two LayerDrawables and one ColorDrawable :

  Drawable blueDrawable = getResources().getDrawable(R.drawable.progress_blue); Drawable redDrawable = getResources().getDrawable(R.drawable.progress_red); Drawable greenDrawable = getResources().getDrawable(R.drawable.progress_green); 

No matter where I move the third ProgressBar in the layout and in the code, or try to exchange progressDrawable attributes, the one that references my third XML Drawable shows no progress and gives me ColorDrawable .

Interestingly, I found that just creating a new XML file in my patch folder fixes the problem. This leads me to believe that there is a problem with how Android packs or loads my resources, but it’s hard for me to figure out how to identify and fix the root problem.

I also cannot reproduce the problem in the new application.

How to continue tracking the source of this problem?

progressDrawable XML:

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <solid android:color="@android:color/transparent" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <solid android:color="@android:color/transparent" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <solid android:color="@color/myapp_green" /> <!-- The other two drawbles only change this color --> </shape> </clip> </item> </layer-list> 

colors.xml:

 <resources> <color name="myapp_red">#dd514c</color> <color name="myapp_green">#5eb95e</color> <color name="myapp_blue">#0e90d2</color> </resources> 

Refresh from moving progressDrawable attributes around

  • red, blue, green: the third is broken.
  • red, green, green: 2nd and 3rd are broken.
  • blue, green, red: 2nd broken.
  • blue, red, blue: all works
  • green, green, green: all works
  • green, green, red: all works
  • green, blue, red: all works
+7
android android-drawable
source share
2 answers

If you change the order, from:

 Drawable blueDrawable = getResources().getDrawable(R.drawable.progress_blue); Drawable redDrawable = getResources().getDrawable(R.drawable.progress_red); Drawable greenDrawable = getResources().getDrawable(R.drawable.progress_green); 

eg:

 Drawable redDrawable = getResources().getDrawable(R.drawable.progress_red); Drawable greenDrawable = getResources().getDrawable(R.drawable.progress_green); Drawable blueDrawable = getResources().getDrawable(R.drawable.progress_blue); 

What is the problem of greenDrawable or another 3rd position (blueDrawable)?

+3
source share

If you don’t even see the progress bar, maybe you have a flashlight stuck somewhere?

Try setting the style attribute:

 style="@android:style/Widget.ProgressBar.Inverse" 
0
source share

All Articles