How would one fetch the accent color set in styles, like below, programmatically?
<item name="android:colorAccent">@color/material_green_500</item>
Android system accent colors can be changed by going to Settings > Wallpaper & style > Basic colors and picking your favorite color. You can also go to Wallpaper colors to let Android pick the colors based on your wallpaper.
Go to Settings->About Phone->Build Number and tap on it 7 times. You will get the message “you are now a developer” and developer options will get enabled. Go to Settings->System->Developer options–>Scroll down to accent colors. Now, choose the accent color that you want to enable and you are done.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With