How would one fetch the accent color set in styles, like below, programmatically?
<item name="android:colorAccent">@color/material_green_500</item>
You can fetch it from the current theme in this way:
private int fetchAccentColor() { TypedValue typedValue = new TypedValue(); TypedArray a = mContext.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent }); int color = a.getColor(0, 0); a.recycle(); return color; }
2.1m questions
2.1m answers
60 comments
57.0k users