m.i.n.a.r.
m.i.n.a.r.

Reputation: 1118

Get Android system accent color (Android 10 System color accent)

This question should be simple, but i didn't find an answer. I have an app with selectable accent, and i'm trying to add an option to use the android system accent (apps like Lawnchair have such an option). In the style for the system accent, i tried to get this accent in every way possible:

?android:colorAccent

?android:attr/colorAccent

?attr/colorAccent

And this is the style:

<style name="AppTheme.systemAccent" parent="AppTheme">
    <item name="colorAccent">???</item>
</style>

Nothing seems to work and the app crashes, but i'm certain that this is possible. The accent selection, when i use normal colors, works fine. Where am i wrong?

EDIT: Just to be clear, i'm trying to get the system accent color, i.e. the system wide color used in settings, notification panel and so on. This color is now selectable in Android 10 and was selectable before in rom like the Oxygen OS. Let's say i select a red accent in settings->customization on my Android 10 device. I want to get this red accent in my app

Upvotes: 5

Views: 4615

Answers (4)

Arctiic
Arctiic

Reputation: 145

You can use SetEdit (or similar application) to enumerate it. Look for the sysui_type_accent_color key under the Secure table. You can also do this programatically, if I recall correctly, through adb shell via busybox content.

Upvotes: 0

Tarik Weiss
Tarik Weiss

Reputation: 345

Okay. I did some intensive research and trial and error. After that I found out, that I could access a private property @*android:color/accent_device_default_light. BUT this is just possible if you change your parent class for the activity from AppCompatActivity to Activity because the AppCompat can't set up the toolbar with this private property. Further it's not recommended to use private properties because they are likely to get deleted or changed in the future.

Upvotes: 2

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364391

You can get it programmatically:

TypedValue typedValue = new TypedValue();
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this,
     android.R.style.Theme_DeviceDefault);
contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent,
     typedValue, true);
int color = typedValue.data; 

Just to be clear I am referring to the Android Q System color accent:

enter image description here enter image description here

Upvotes: 7

rachna
rachna

Reputation: 124

@color/colorAccent use this ,it's default color in android or you can customize your color in the color.xml

Upvotes: -1

Related Questions