Last active
August 29, 2015 14:12
-
-
Save ok3141/9106e4df26dd9d4ccc06 to your computer and use it in GitHub Desktop.
Get values from attribute
This file contains 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
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