Created
April 1, 2015 01:57
-
-
Save koush/e709991107d4deb38d28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/NightlyNexus/cca0e2703fbe14525473 does not rely on the attribute being a color resource.