How to get accent color programmatically?
问题 How would one fetch the accent color set in styles, like below, programmatically? <item name="android:colorAccent">@color/material_green_500</item> 回答1: 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: This worked for me as well: public static int