Skip to content

Instantly share code, notes, and snippets.

@alorma
Created June 30, 2015 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alorma/4f6c4c8e424a8c96b4ed to your computer and use it in GitHub Desktop.
Save alorma/4f6c4c8e424a8c96b4ed to your computer and use it in GitHub Desktop.
getTheme colors
private int fetchPrimaryColor() {
int colorAccent = Color.parseColor("#FF0000");
int attr = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.attr.colorPrimary : R.attr.colorPrimary;
TypedArray a = getContext().getTheme().obtainStyledAttributes(new int[]{attr});
colorAccent = a.getColor(0, colorAccent);
a.recycle();
return colorAccent;
}
private int fetchAccentColor() {
int colorAccent = Color.parseColor("#00FF00");
int attr = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.attr.colorAccent : R.attr.colorAccent;
TypedArray a = getContext().getTheme().obtainStyledAttributes(new int[]{attr});
colorAccent = a.getColor(0, colorAccent);
a.recycle();
return colorAccent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment