撰写中与主题相关的绘制



我正在将一个项目迁移到组合,我遇到了这个可绘制的,根据主题改变它的颜色

<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>

,

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

有两个不同的参考(暗/光主题)

我已经为compose创建了一个主题。我可以在绘制中使用compose主题的颜色吗?

在默认的Compose模板中有一个名为Theme.kt的文件。你可以为它创建一个自定义的Composable,像这样

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