Skip to content

Instantly share code, notes, and snippets.

@koush
Created April 1, 2015 01:57
Show Gist options
  • Save koush/e709991107d4deb38d28 to your computer and use it in GitHub Desktop.
Save koush/e709991107d4deb38d28 to your computer and use it in GitHub Desktop.
package com.koushikdutta.boilerplate;
import android.content.Context;
import android.graphics.PorterDuff;
import android.util.AttributeSet;
import android.widget.ProgressBar;
public class TintedProgressBar extends ProgressBar {
public TintedProgressBar(Context context) {
super(context);
init(null);
}
public TintedProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
public TintedProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
public void init(AttributeSet attrs) {
TintHelper.getColorPrimary(getContext());
int tintColor = TintHelper.getColorAccent(getContext());
if (attrs != null) {
int color = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res-auto", "tint", 0);
if (color != 0)
tintColor = getContext().getResources().getColor(color);
}
getIndeterminateDrawable().setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
getProgressDrawable().setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
}
}
@NightlyNexus
Copy link

https://gist.github.com/NightlyNexus/cca0e2703fbe14525473 does not rely on the attribute being a color resource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment