Skip to content

Instantly share code, notes, and snippets.

@ok3141
Created December 24, 2014 15:07
Show Gist options
  • Save ok3141/dbc06ae56258cb632a14 to your computer and use it in GitHub Desktop.
Save ok3141/dbc06ae56258cb632a14 to your computer and use it in GitHub Desktop.
Color state list programmatically
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