To build a Hello World app with Jetpack Compose, create a new project in Android Studio using the Empty Activity template, which is Compose-based, then replace the generated Greeting composable with your own text and run it. The screen is defined by a @Composable function called from setContent inside your MainActivity. No XML layout is needed.
This guide walks through the project, explains each part of the generated code and shows how to add a preview.
Compose requires Kotlin and a minimum SDK of API 21 or higher, and the project wizard configures the Compose compiler plugin and dependencies for you.
HelloCompose and a package name such as com.example.hellocompose.The template generates code similar to this, and the exact names can differ slightly between versions.
Here is what each part does:
ComponentActivity is the base class for activities that host Compose.setContent replaces the old setContentView(R.layout...) call. The block inside it is the root of your UI.MaterialTheme supplies colours, typography and shapes from Material 3 to everything inside it.Surface paints a background using the theme colour.Greeting is a composable function. By convention its name starts with a capital letter, and it returns nothing because it emits UI.Modifier is a chain of instructions for size, padding, click handling and more.Select a device or emulator in the toolbar and press Run. The screen shows "Hello Android!" centred on the screen.
Change the string passed to Greeting, for example Greeting("Compose"), and run again to see "Hello Compose!".
The @Preview annotation lets Android Studio render a composable in the Design or Split panel without running the app. A preview function must have no parameters, or only parameters with defaults or preview providers. Change the text in GreetingPreview and the preview refreshes. Previews do not replace testing on a device, but they make layout work much faster.
You can extend the same project with state to see Compose react to a click.
This needs imports for Column, Button, remember, mutableIntStateOf, getValue and setValue. Android Studio can add them with Alt+Enter. Every click increments the state, and Compose redraws the Text.
setContent or from another composable.ui-tooling is present.@Composable: confirm that the Compose compiler plugin and dependencies are in the module build file.No. A Compose app can have no layout files at all. The manifest and resources such as strings and drawables are still used.
Compose style guidelines treat composables that emit UI like classes or components, so they use PascalCase.
ComponentActivity is the lightweight base class used by Compose. AppCompatActivity extends it and adds support for the older AppCompat View features.
No. Composable functions must be written in Kotlin.
A Compose Hello World is a @Composable function such as Greeting, called inside setContent in a ComponentActivity. Create the project with the Empty Activity template, edit the text, add a @Preview for fast feedback, and run it. State and modifiers extend the same pattern to full screens.