Glance는 색상 테마를 관리하는 API를 제공합니다. 다른 스타일 속성의 경우
TextStyle와 같은 최상위 수준 변수를 선언하세요.
색상 추가
Glance는 즉시 사용 가능한 Material 색상을 구현합니다.
기본 제공 테마에서 다음과 같이 최상위 컴포저블을 GlanceTheme로 래핑합니다.
다음 예시를 참고하세요.
동적 색상을 지원하는 기기에서 이 테마는
사용자별 플랫폼 색상을 사용할 수 있습니다. 다른 기기에서는 Material
기준 테마입니다. GlanceTheme.colors을 사용하여 래핑된 색상의 색상으로 스타일 지정
있습니다. 색상이 필요한 곳에 테마의 이러한 값을 사용하면 됩니다.
테마를 맞춤설정하려면 colors를 GlanceTheme에 전달하면 됩니다. 한눈에 보기
androidx.glance:glance-material 상호 운용성 라이브러리를 제공합니다.
Material 2 및 Material 3 색상의 androidx.glance:glance-material3
도움이 될 수 있습니다
예를 들어 앱의 기존 머티리얼 색상을 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)}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-25(UTC)
[[["이해하기 쉬움","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`)."]]