Ответ
Добавь зависимости в build.gradle (Module):
implementation "androidx.compose.ui:ui:1.6.0"
implementation "androidx.compose.material:material:1.6.0"
implementation "androidx.compose.ui:ui-tooling-preview:1.6.0"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.6.0"
debugImplementation "androidx.compose.ui:ui-tooling:1.6.0"
Для интеграции в существующую активити:
- Создай
ComposeViewв XML или программно - Установи
setContentс Compose-контентом
Пример в XML:
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
В коде активити:
findViewById<ComposeView>(R.id.compose_view).setContent {
MaterialTheme {
// Твой Compose-код здесь
Text("Hello Compose!")
}
}
Можно постепенно мигрировать отдельные экраны или компоненты. Compose работает вместе с традиционными View.