What is the Jetpack Compose?

What is the Jetpack Compose?

What is the Jetpack Compose ?

Jetpack Compose is Android’s recommended modern toolkit for building native UI. It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Column() {
                MessageCard(name = "Alli")
                MessageCard(name = "Oybek")
            }

        }
    }
}
@Composable
fun MessageCard(name:String){
    Text(text = "Hello $name")
}
@Preview
@Composable
fun PreviewMessageCard(){
    MessageCard(name = "Android")
}
  • setContentView

    The setContent block defines the activity's layout where composable functions are called.

  • Composable

    To make a function composable, add the @Composable annotation. To try this out, define a MessageCard function which is passed a name, and uses it to configure the text element.

    • Preview

The @Preview annotation lets you preview your composable functions within Android Studio without having to build and install the app to an Android device or emulator.