Kotlin with Jetpack Compose — Cards

Maneesha Erandi
3 min readMay 18, 2023

Cards are commonly used components in mobile development. Cards can hold the content we want inside them and give a better look for the UI. Cards have the elevation property that we can use to display a shadow effect. In Jetpack compose, we have the Card component for this.

Card with properties

@Composable
fun Card(
modifier: Modifier = Modifier,
shape: Shape = MaterialTheme.shapes.medium,
backgroundColor: Color = MaterialTheme.colors.surface,
contentColor: Color = contentColorFor(backgroundColor),
border: BorderStroke? = null,
elevation: Dp = 1.dp,
content: @Composable () -> Unit
)

Simple usage

Card(){
AnyComposableFunction()
}

Card with a border

You can define the border color and weight with BorderStroke which we can pass to the border param.

            Card(
modifier = Modifier.padding(16.dp),
shape = MaterialTheme.shapes.medium,
elevation = 4.dp,
border = BorderStroke(2.dp, Color.Black)
) {
Column(
modifier = Modifier.padding(16.dp)
) {
Text(
text = "Card Title",
style = MaterialTheme.typography.h6…

--

--