Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  3.  
  4. <item
  5. android:id="@android:id/background"
  6. android:drawable="#F6F3F1" />
  7. <item android:id="@android:id/secondaryProgress">
  8. <scale
  9. android:drawable="#DE0012"
  10. android:scaleWidth="100%" />
  11. </item>
  12. <item android:id="@android:id/progress">
  13. <scale
  14. android:drawable="#DE0012"
  15. android:scaleWidth="100%" />
  16. </item>
  17. </layer-list>
  18.  
  19. LayerDrawable layers = (LayerDrawable) getResources().getDrawable(R.drawable.style_progress_bar);
  20. int color = getResources().getColor(colorId); // This is the ID of the new color. I use it elsewhere so this should be 100% good
  21.  
  22. layers.getDrawable(1).setColorFilter(color, PorterDuff.Mode.MULTIPLY);
  23. layers.getDrawable(2).setColorFilter(color, PorterDuff.Mode.MULTIPLY);
  24.  
  25. // I even called invalidate(); after all this. Nothing changed
  26.  
  27. <scale
  28. android:drawable="#DE0012"
  29. android:scaleWidth="100%" />
  30.  
  31. private Drawable createDrawable(int colorId) {
  32. LayerDrawable layers = (LayerDrawable) getResources().getDrawable(R.drawable. style_progress_bar);
  33. int color = getResources().getColor(colorId);
  34. try {
  35. ScaleDrawable first = (ScaleDrawable) layers.getDrawable(1);
  36. ScaleDrawable second = (ScaleDrawable) layers.getDrawable(2);
  37. ColorDrawable secondaryColor = (ColorDrawable) first.getDrawable();
  38. secondaryColor.setColor(color);
  39. ColorDrawable primaryColor = (ColorDrawable) second.getDrawable();
  40. primaryColor.setColor(color);
  41. } catch (ClassCastException e) {
  42. e.printStackTrace();
  43. }
  44. return layers;
  45. }
  46.  
  47. progressBar.setProgressDrawable(createDrawable(colorId));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement