Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item
- android:id="@android:id/background"
- android:drawable="#F6F3F1" />
- <item android:id="@android:id/secondaryProgress">
- <scale
- android:drawable="#DE0012"
- android:scaleWidth="100%" />
- </item>
- <item android:id="@android:id/progress">
- <scale
- android:drawable="#DE0012"
- android:scaleWidth="100%" />
- </item>
- </layer-list>
- LayerDrawable layers = (LayerDrawable) getResources().getDrawable(R.drawable.style_progress_bar);
- int color = getResources().getColor(colorId); // This is the ID of the new color. I use it elsewhere so this should be 100% good
- layers.getDrawable(1).setColorFilter(color, PorterDuff.Mode.MULTIPLY);
- layers.getDrawable(2).setColorFilter(color, PorterDuff.Mode.MULTIPLY);
- // I even called invalidate(); after all this. Nothing changed
- <scale
- android:drawable="#DE0012"
- android:scaleWidth="100%" />
- private Drawable createDrawable(int colorId) {
- LayerDrawable layers = (LayerDrawable) getResources().getDrawable(R.drawable. style_progress_bar);
- int color = getResources().getColor(colorId);
- try {
- ScaleDrawable first = (ScaleDrawable) layers.getDrawable(1);
- ScaleDrawable second = (ScaleDrawable) layers.getDrawable(2);
- ColorDrawable secondaryColor = (ColorDrawable) first.getDrawable();
- secondaryColor.setColor(color);
- ColorDrawable primaryColor = (ColorDrawable) second.getDrawable();
- primaryColor.setColor(color);
- } catch (ClassCastException e) {
- e.printStackTrace();
- }
- return layers;
- }
- progressBar.setProgressDrawable(createDrawable(colorId));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement