DEV Community

DeepaShreeMulay
DeepaShreeMulay

Posted on

Jetpack Compose

Jetpack Compose is a modern toolkit for building user interfaces in Android. It is a reactive and declarative framework that simplifies the process of creating and managing UI elements, and allows for a more efficient and flexible way to build apps. Jetpack Compose allows developers to create UI elements using simple, expressive code and eliminates the need for complex layout XML files. It also offers built-in support for animations, accessibility, and other advanced features.

@Composable
fun MyButton() {
    Column(
        modifier = Modifier.fillMaxWidth().padding(16.dp),
        verticalArrangement = Arrangement.Center,
        horizontalGravity = Alignment.CenterHorizontally
    ) {
        Button(
            onClick = { /* Perform action */ },
            modifier = Modifier.padding(8.dp),
            text = "Click me!"
        )
    }
}
Enter fullscreen mode Exit fullscreen mode

This code sample creates a button that is centered within a column, with a padding of 16 dp around the column, and 8 dp around the button. The button’s text is set to “Click me!” and when the button is clicked, it will perform an action.

You can use this button inside your compose function and can apply any customize you want for example you can change the text color by adding MaterialTheme.typography() and passing your textColor.

Top comments (0)