setContent: Onde sua Interface Começa
Conecte sua árvore de Composable à Activity.
setContent: Onde sua Interface Começa é uma aula grátis de Jetpack Compose Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Jetpack Compose Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Jetpack Compose Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Connecting Compose to Android
Your Composables need a home. The setContent call inside an Activity is the bridge that hands your UI tree to the Android screen. 🔗
Inside onCreate
You call setContent from an Activity onCreate. That is the moment Android tells your app it is time to show a screen.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { Greeting() }
}It Takes a Lambda
setContent accepts a lambda, and inside that block you call your Composables. Everything in the braces becomes the screen content.
setContent {
Greeting("Compose")
}The Lambda Is Composable
That lambda is itself a @Composable scope. So you can call any Composable directly inside it, no extra setup required.
One Root Composable
A clean app calls a single root Composable here, often your whole app or theme, which then nests everything else below it.
setContent {
MyApp()
}Wrap in Your Theme
Most apps wrap the root in their theme so colors and fonts apply everywhere. The theme is just another Composable around your UI.
setContent {
MyAppTheme {
MyApp()
}
}Replaces setContentView
In the old View system you called setContentView with an XML layout. Compose swaps that for setContent with a Composable lambda.
Extends ComponentActivity
The Activity that uses setContent typically extends ComponentActivity, the lightweight base class Compose is designed to work with.
class MainActivity : ComponentActivity() {
// onCreate with setContent
}Where the Tree Mounts
setContent is the entry point. From here Compose builds, lays out, and draws the whole tree of Composables you call inside it.
Add Surface for Background
Wrapping content in a Surface gives a themed background and elevation, a common first child under your theme.
setContent {
MyAppTheme {
Surface { MyApp() }
}
}One setContent Per Screen
You normally call setContent once per Activity. To show different content, you change state inside the tree, not call setContent again.
Quick Check
A final check on where Compose UI starts.
Recap
You now know where it all begins: call setContent in onCreate, pass a Composable lambda, wrap it in your theme, and Compose draws your app. 🎉
Perguntas Frequentes
A aula “setContent: Onde sua Interface Começa” é grátis?
Sim — o texto completo de “setContent: Onde sua Interface Começa” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Jetpack Compose Academy, atualize para CoddyKit PRO. O curso de Jetpack Compose Academy inclui 4 aulas no total.
O que vou aprender em “setContent: Onde sua Interface Começa”?
Conecte sua árvore de Composable à Activity. Você pratica Jetpack Compose Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Jetpack Compose Academy?
Nenhuma experiência prévia é necessária. Jetpack Compose Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “setContent: Onde sua Interface Começa”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Jetpack Compose Academy?
Sim. Cada aula de Jetpack Compose Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Escrevendo uma Função @Composable
- Previews em Tempo Real com @Preview
- Chamando Composables a partir de Composables
- setContent: Onde sua Interface Começa