Jetpack Compose Tutorial is small Android Jetpack Compose tutorial by Google → good to start
@Composable annotation to the function nameonCreate create a setContent block and call there the composablesetContent block defines the activity's layout where composable functions are called. @Preview annotation helps to see the previews of Composable functions within Android Studio@Preview should have NO parameters Column → builds elements vertically:@Composable fun MessageCard(msg: Message) { Column { Text(text = msg.author) Text(text = msg.body) } }
Row → builds elements horizontally:@Composable fun MessageCard(msg: Message) { // Add padding around our message Row(modifier = Modifier.padding(all = 8.dp)) { Image( painter = painterResource(R.drawable.profile_picture), contentDescription = "Contact profile picture", modifier = Modifier // Set image size to 40 dp .size(40.dp) // Clip image to be shaped as a circle .clip(CircleShape) ) // Add a horizontal space between the image and the column Spacer(modifier = Modifier.width(8.dp)) Column { Text(text = msg.author) // Add a vertical space between the author and message texts Spacer(modifier = Modifier.height(4.dp)) Text(text = msg.body) } } }
MessageCard function with the Material theme created in your project, ComposeTutorialTheme, as well as a SurfaceMaterialTheme.colorShemeMaterialTheme.typography.titleSmallMaterialTheme.typography. …MaterialTheme.shapes.mediumMaterialTheme.shapes. …@Preview (uiMode = Configuration.UI_MODE_NIGHT_YES)LazyColumn and LazyRow because they shows only elements, which are on the screen remembermutableStateOf