Theme dependent drawables in compose

Viewed 104

I'm migrating a project to compose and I came across this drawable that changes its colors based on the theme

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="70dp"
android:height="70dp"
android:viewportWidth="70"
android:viewportHeight="70">
<path
    android:fillColor="@color/color_surface"
    android:pathData="M35,35m-35,0a35,35 0,1 1,70 0a35,35 0,1 1,-70 0" />
<path
    android:fillColor="@color/sync_profile_fill"
    android:pathData="M35,35m-35,0a35,35 0,1 1,70 0a35,35 0,1 1,-70 0" />
<path
    android:fillColor="@color/transparent"
    android:pathData="M35,35.2468C29.8084,35.2468 21.3889,38.3349 21.3889,44.4649C21.3889,44.4649 23.6574,50.5554 35,50.5554C46.3426,50.5554 48.6111,44.4649 48.6111,44.4649C48.6111,38.3349 40.1917,35.2468 35,35.2468ZM35,35.2468C39.2956,35.2468 42.7778,31.7093 42.7778,27.3456C42.7778,22.9818 39.2956,19.4443 35,19.4443C30.7045,19.4443 27.2222,22.9818 27.2222,27.3456C27.2222,31.7093 30.7045,35.2468 35,35.2468Z"
    android:strokeWidth="2"
    android:strokeColor="@color/sync_profile_stroke" />
</vector>

where

    android:fillColor="@color/color_surface"
    android:fillColor="@color/sync_profile_fill"

have 2 different references (dark/light theme)

I already created a theme for compose. Can I use the colors from the compose theme in the drawable?

1 Answers

There is a file in the default Compose template called Theme.kt. You can create a little custom Composable for it, something like this

@Composable
fun getThemedColour() : Color{ //This is the Compose Color, double check while importing
 if(isSystemInDarkTheme()) return Blue else return Red
}
Related