たとえば、アプリの既存のマテリアル カラーを ColorProviders に指定します。
API を使用して Glance のカラーパターンを作成します。以下のスニペットをご覧ください。
// Remember, use the Glance imports// import androidx.glance.material3.ColorProviders// Example Imports from your own app// import com.example.myapp.ui.theme.DarkColors// import com.example.myapp.ui.theme.LightColorsobjectMyAppWidgetGlanceColorScheme{valcolors=ColorProviders(light=LightColors,dark=DarkColors)}
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-25 UTC。"],[],[],null,["Glance provides an API to manage the color theme. For other style attributes,\nsuch as [`TextStyle`](/reference/kotlin/androidx/compose/ui/text/TextStyle), declare top-level variables.\n\nAdd colors\n\nGlance provides an implementation of Material colors out of the box. To use the\nbuilt-in theme, wrap your top level composable with `GlanceTheme`, as shown in\nthe following example.\n\nOn devices that support dynamic colors, this theme is derived from the\nuser-specific platform colors. On other devices, this falls back to the Material\nbaseline theme. Use `GlanceTheme.colors` to style with colors from the wrapped\ntheme. You can use these values from the theme anywhere a color is needed.\n\n\n```kotlin\noverride suspend fun provideGlance(context: Context, id: GlanceId) {\n\n provideContent {\n GlanceTheme {\n MyContent()\n }\n }\n}\n\n@Composable\nprivate fun MyContent() {\n\n Image(\n colorFilter = ColorFilter.tint(GlanceTheme.colors.secondary),\n // ...\n\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/glance/GlanceSnippets.kt#L756-L777\n```\n\n\u003cbr /\u003e\n\nTo customize the theme, you can pass the `colors` to the `GlanceTheme`. Glance\nprovides the `androidx.glance:glance-material` interoperability library for\nMaterial 2, and `androidx.glance:glance-material3` for Material 3 colors\nsupport.\n\nFor example, provide your app's existing material colors to the `ColorProviders`\nAPI to create a Glance color scheme, as shown in the following snippet:\n\n\n```kotlin\n// Remember, use the Glance imports\n// import androidx.glance.material3.ColorProviders\n\n// Example Imports from your own app\n// import com.example.myapp.ui.theme.DarkColors\n// import com.example.myapp.ui.theme.LightColors\n\nobject MyAppWidgetGlanceColorScheme {\n\n val colors = ColorProviders(\n light = LightColors,\n dark = DarkColors\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/glance/GlanceSnippets.kt#L784-L797\n```\n\n\u003cbr /\u003e\n\nProvide the colors from the scheme to the `GlanceTheme` that wraps all your\ncomposables, as shown in the following example:\n\n\n```kotlin\noverride suspend fun provideGlance(context: Context, id: GlanceId) {\n // ...\n\n provideContent {\n GlanceTheme(colors = MyAppWidgetGlanceColorScheme.colors) {\n MyContent()\n }\n }\n}\n\n@Composable\nprivate fun MyContent() {\n\n Image(\n colorFilter = ColorFilter.tint(GlanceTheme.colors.secondary),\n // ...\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/glance/GlanceSnippets.kt#L800-L820\n```\n\n\u003cbr /\u003e\n\nIf you prefer to use dynamic colors from the wallpaper when supported, and your\napp's color scheme otherwise, you can conditionally pass your app's color scheme\nin the `GlanceTheme`. This is shown in the following snippet:\n\n\n```kotlin\noverride suspend fun provideGlance(context: Context, id: GlanceId) {\n\n provideContent {\n GlanceTheme(\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.S)\n GlanceTheme.colors\n else\n MyAppWidgetGlanceColorScheme.colors\n ) {\n MyContent()\n }\n }\n}\n\n@Composable\nprivate fun MyContent() {\n // ...\n Image(\n colorFilter = ColorFilter.tint(GlanceTheme.colors.secondary),\n // ...\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/glance/GlanceSnippets.kt#L834-L858\n```\n\n\u003cbr /\u003e\n\nAdd shapes\n\nTo provide special shapes or shadows to your app widget, use the Android\nDrawables API.\n\nFor example, the following snippet shows how to create a drawable (a shape): \n\n \u003cshape xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n \u003ccorners android:radius=\"16dp\"/\u003e\n \u003cstroke android:color=\"@color/outline_color\" android:width=\"1dp\"/\u003e\n \u003c/shape\u003e \n https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/res/drawable/button_outline.xml#L18-L21\n\nProvide it to the target composable:\n\n\n```kotlin\nGlanceModifier.background(\n imageProvider = ImageProvider(R.drawable.button_outline)\n)https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/glance/GlanceSnippets.kt#L866-L868\n```\n\n\u003cbr /\u003e\n\n| **Note:** You can use the Android resource folder structure to define different shapes or other resources for any type of configuration (e.g., `values-night`)."]]