Created
December 24, 2014 15:07
-
-
Save ok3141/dbc06ae56258cb632a14 to your computer and use it in GitHub Desktop.
Color state list programmatically
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 ColorStateList createThemedColorStateList(Context context) { | |
TypedValue typedValue = new TypedValue(); | |
context.getTheme().resolveAttribute(R.attr.selectableItemTextColor, typedValue, true); | |
int[] attribute = new int[]{R.attr.selectableItemTextColor}; | |
TypedArray array = context.obtainStyledAttributes(typedValue.resourceId, attribute); | |
final int color; | |
try { | |
color = Objects.notNull(array.getColorStateList(0)).getDefaultColor(); | |
} finally { | |
array.recycle(); | |
} | |
return new ColorStateList( | |
new int[][]{ | |
new int[]{android.R.attr.state_pressed}, | |
new int[]{}, | |
}, | |
new int[]{ | |
getSingleton(SettingsManager.class).getPrimaryColor(), | |
color, | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment