I want to use M3 colors like ?attr/colorPrimary
in my app's launcher icon. I know this is possible because my phone's Settings app does it. I've looked around quite a bit and couldn't find anything related to this.
I've tried setting my foreground icon color <path android:fillColor="?attr/colorPrimary" ... />
, but this just gave a blank icon.
I even tried setting a tint to the adaptive icon <foreground android:tint="?attr/colorPrimary" ... />
, but this didn't have any effect.
From the official source code of Android 12's Settings app, it looks like they're using the following private property as the launcher icon's background color.
This probably works for Android 12 Pixel devices as it's normally not recommended to use private properties because there's a chance they won't exist in the system. In other words, this isn't a good solution.
This is the solution I finally went with which worked nicely for me.
values/colors.xml
values/colors.xml (v31)
And finally I used
@color/launcher_icon_background_color
in my foreground icon'sfillColor
.