Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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> 
like image 724
Jakob Avatar asked Dec 22 '14 22:12

Jakob


People also ask

How do I make my computer have an accent color?

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.

How do you change the color of accents on Android?

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.


1 Answers

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; } 
like image 143
rciovati Avatar answered Oct 12 '22 23:10

rciovati