Skip to content

Instantly share code, notes, and snippets.

@ok3141
Last active August 29, 2015 14:12
Show Gist options
  • Save ok3141/9106e4df26dd9d4ccc06 to your computer and use it in GitHub Desktop.
Save ok3141/9106e4df26dd9d4ccc06 to your computer and use it in GitHub Desktop.
Get values from attribute
private static int getDefaultColorFromAttribute(Context context, int attr) {
TypedArray array = obtainStyledAttributeResource(context, attr);
final int color;
try {
color = notNull(array.getColorStateList(0)).getDefaultColor();
} finally {
array.recycle();
}
return color;
}
private static TypedArray obtainStyledAttributeResource(Context context, int attr) {
TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(attr, typedValue, true);
int[] attribute = new int[]{attr};
return context.obtainStyledAttributes(typedValue.resourceId, attribute);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment