Compose 내 테마 분석
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Jetpack Compose의 테마는 여러 개의 하위 수준 구성과 관련 API로 이루어져 있습니다. 이러한 요소는 MaterialTheme
의 소스 코드에서 확인할 수 있으며 맞춤 디자인 시스템에 적용할 수도 있습니다.
테마 시스템 클래스
일반적으로 테마는 공통된 시각적 개념과 동작 개념을 그룹화하는 여러 개의 하위 시스템으로 구성됩니다. 이러한 시스템은 테마 설정 값이 있는 클래스를 사용하여 모델링할 수 있습니다.
예를 들어 MaterialTheme
에는 ColorScheme
(색상 시스템), Typography
(서체 시스템), Shapes
(도형 시스템) 등이 포함됩니다.
@Immutable
data class ColorSystem(
val color: Color,
val gradient: List<Color>
/* ... */
)
@Immutable
data class TypographySystem(
val fontFamily: FontFamily,
val textStyle: TextStyle
)
/* ... */
@Immutable
data class CustomSystem(
val value1: Int,
val value2: String
/* ... */
)
/* ... */
테마 시스템 컴포지션 로컬
테마 시스템 클래스는 컴포지션 트리에 CompositionLocal
인스턴스 형태로 암시적으로 제공됩니다. 그러면 구성 가능한 함수에서 테마 설정 값을 정적으로 참조할 수 있습니다.
CompositionLocal
에 관한 자세한 내용은 CompositionLocal을 사용한 로컬 범위 지정 데이터 가이드를 참고하세요.
val LocalColorSystem = staticCompositionLocalOf {
ColorSystem(
color = Color.Unspecified,
gradient = emptyList()
)
}
val LocalTypographySystem = staticCompositionLocalOf {
TypographySystem(
fontFamily = FontFamily.Default,
textStyle = TextStyle.Default
)
}
val LocalCustomSystem = staticCompositionLocalOf {
CustomSystem(
value1 = 0,
value2 = ""
)
}
/* ... */
테마 함수
테마 함수는 진입점이자 기본 API입니다. 이 함수는 로직에 필요한 경우 실제 값을 사용하여 테마 시스템 CompositionLocal
(CompositionLocalProvider
를 통해 컴포지션 트리에 제공됨)의 인스턴스를 구성합니다.
content
매개변수를 사용하면 중첩된 컴포저블이 계층 구조를 기준으로 테마 설정 값에 액세스할 수 있습니다.
@Composable
fun Theme(
/* ... */
content: @Composable () -> Unit
) {
val colorSystem = ColorSystem(
color = Color(0xFF3DDC84),
gradient = listOf(Color.White, Color(0xFFD7EFFF))
)
val typographySystem = TypographySystem(
fontFamily = FontFamily.Monospace,
textStyle = TextStyle(fontSize = 18.sp)
)
val customSystem = CustomSystem(
value1 = 1000,
value2 = "Custom system"
)
/* ... */
CompositionLocalProvider(
LocalColorSystem provides colorSystem,
LocalTypographySystem provides typographySystem,
LocalCustomSystem provides customSystem,
/* ... */
content = content
)
}
테마 객체
테마 시스템에 액세스하는 방법은 편의성 속성이 있는 객체를 사용하는 것입니다. 일관성을 위해 객체 이름은 테마 함수와 동일하게 지정되는 경향이 있습니다. 편의성 속성은 현재 컴포지션 로컬을 가져오기만 합니다.
// Use with eg. Theme.colorSystem.color
object Theme {
val colorSystem: ColorSystem
@Composable
get() = LocalColorSystem.current
val typographySystem: TypographySystem
@Composable
get() = LocalTypographySystem.current
val customSystem: CustomSystem
@Composable
get() = LocalCustomSystem.current
/* ... */
}
추천 서비스
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-27(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-27(UTC)"],[],[],null,["Themes in Jetpack Compose are made up of a number of lower-level constructs\nand related APIs. These can be seen in the\n[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/MaterialTheme.kt)\nof `MaterialTheme` and can also be applied in custom design systems.\n\nTheme system classes\n\nA theme is typically made up of a number of subsystems that group common visual and\nbehavioral concepts. These systems can be modeled with classes which have\ntheming values.\n\nFor example, `MaterialTheme` includes\n[`ColorScheme`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/ColorScheme.kt)\n(color system),\n[`Typography`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Typography.kt)\n(typography system), and\n[`Shapes`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Shapes.kt)\n(shape system).\n| **Note:** Classes should be annotated with [`Stable`](/reference/kotlin/androidx/compose/runtime/Stable) or [`@Immutable`](/reference/kotlin/androidx/compose/runtime/Immutable) to provide information to the Compose compiler. To learn more, check out the [Lifecycle of composables guide](/develop/ui/compose/lifecycle#skipping).\n\n\n```kotlin\n@Immutable\ndata class ColorSystem(\n val color: Color,\n val gradient: List\u003cColor\u003e\n /* ... */\n)\n\n@Immutable\ndata class TypographySystem(\n val fontFamily: FontFamily,\n val textStyle: TextStyle\n)\n/* ... */\n\n@Immutable\ndata class CustomSystem(\n val value1: Int,\n val value2: String\n /* ... */\n)\n\n/* ... */https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/designsystems/ThemeAnatomySnippets.kt#L31-L52\n```\n\n\u003cbr /\u003e\n\nTheme system composition locals\n\nTheme system classes are implicitly provided to the composition tree as\n[`CompositionLocal`](/reference/kotlin/androidx/compose/runtime/CompositionLocal)\ninstances. This allows theming values to be statically referenced in composable\nfunctions.\n\nTo learn more about `CompositionLocal`, check out the\n[Locally scoped data with CompositionLocal guide](/develop/ui/compose/compositionlocal).\n| **Note:** You can create a class's `CompositionLocal` with [`compositionLocalOf`](/reference/kotlin/androidx/compose/runtime/package-summary#compositionlocalof) or [`staticCompositionLocalOf`](/reference/kotlin/androidx/compose/runtime/package-summary#staticcompositionlocalof). These functions have a `defaultFactory` trailing lambda to provide fallback values of the same type that they're providing. It's a good idea to use reasonable defaults like `Color.Unspecified`, `TextStyle.Default`, etc.\n\n\n```kotlin\nval LocalColorSystem = staticCompositionLocalOf {\n ColorSystem(\n color = Color.Unspecified,\n gradient = emptyList()\n )\n}\n\nval LocalTypographySystem = staticCompositionLocalOf {\n TypographySystem(\n fontFamily = FontFamily.Default,\n textStyle = TextStyle.Default\n )\n}\n\nval LocalCustomSystem = staticCompositionLocalOf {\n CustomSystem(\n value1 = 0,\n value2 = \"\"\n )\n}\n\n/* ... */https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/designsystems/ThemeAnatomySnippets.kt#L56-L77\n```\n\n\u003cbr /\u003e\n\nTheme function\n\nThe theme function is the entry point and primary API. It constructs instances\nof the theme system `CompositionLocal`s --- using real values any logic\nrequired --- that are provided to the composition tree with\n[`CompositionLocalProvider`](/reference/kotlin/androidx/compose/runtime/package-summary#compositionlocalprovider).\nThe `content` parameter allows nested composables to access theming values\nrelative to the hierarchy.\n\n\n```kotlin\n@Composable\nfun Theme(\n /* ... */\n content: @Composable () -\u003e Unit\n) {\n val colorSystem = ColorSystem(\n color = Color(0xFF3DDC84),\n gradient = listOf(Color.White, Color(0xFFD7EFFF))\n )\n val typographySystem = TypographySystem(\n fontFamily = FontFamily.Monospace,\n textStyle = TextStyle(fontSize = 18.sp)\n )\n val customSystem = CustomSystem(\n value1 = 1000,\n value2 = \"Custom system\"\n )\n /* ... */\n CompositionLocalProvider(\n LocalColorSystem provides colorSystem,\n LocalTypographySystem provides typographySystem,\n LocalCustomSystem provides customSystem,\n /* ... */\n content = content\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/designsystems/ThemeAnatomySnippets.kt#L81-L106\n```\n\n\u003cbr /\u003e\n\nTheme object\n\nAccessing theme systems is done using an object with convenience properties. For\nconsistency, the object tends to be named the same as the theme function. The\nproperties simply get the current composition local.\n\n\n```kotlin\n// Use with eg. Theme.colorSystem.color\nobject Theme {\n val colorSystem: ColorSystem\n @Composable\n get() = LocalColorSystem.current\n val typographySystem: TypographySystem\n @Composable\n get() = LocalTypographySystem.current\n val customSystem: CustomSystem\n @Composable\n get() = LocalCustomSystem.current\n /* ... */\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/designsystems/ThemeAnatomySnippets.kt#L110-L122\n```\n\n\u003cbr /\u003e\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Locally scoped data with CompositionLocal](/develop/ui/compose/compositionlocal)\n- [Custom design systems in Compose](/develop/ui/compose/designsystems/custom)\n- [Material Design 3 in Compose](/develop/ui/compose/designsystems/material3)"]]