Button in Android using Jetpack Compose Last Updated : 20 Feb, 2025 Comments Improve Suggest changes Like Article Like Report Jetpack Compose is a new toolkit provided by Google. This is useful for designing beautiful UI designs. A Button is a UI component in Android which is used to navigate between different screens. With the help of a button, the user can interact with your app and perform multiple actions inside your application. In this article, we will take a look at the implementation of buttons in Android using Jetpack Compose. Attributes of the Button WidgetAttributeDescriptiononClickTo perform an action when your button is clicked by the user.modifierthis parameter is used to add padding to our button. enabledto enable or disable your button. borderthis parameter is used to add a border stroke to our button.shape this parameter is used to add shape to our button.Text()this parameter will be used to add text which is to be displayed on your button. colorsUsed Customized the button colors for different states (normal, disabled).elevationSet different elevations for the default, pressed, and disabled states.contentPaddingAdded padding inside the button around its content for a better appearance.interactionSourceUsed a default MutableInteractionSource to handle interaction states.contentAdded a Text composable inside the button, with customized text properties like font size, weight, style, and family.Step-by-Step ImplementationStep 1: Create a New Project.To create a new project in the Android Studio Canary Version please refer to How to Create a new Project in Android Studio Canary Version with Jetpack Compose.Step 2: Working with the MainActivity.kt fileNavigate to the app > java > your app’s package name and open the MainActivity.kt file. Inside that file add the below code to it. Comments are added inside the code to understand the code in more detail.MainActivity.kt: MainAcitivity.kt package org.geeksforgeeks.demo import android.os.Bundle import android.widget.Toast import androidx.activity.* import androidx.activity.compose.setContent import androidx.compose.foundation.* import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.* import androidx.compose.ui.graphics.* import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.* import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.* class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { MaterialTheme { Surface(color = MaterialTheme.colorScheme.background) { MyButton() } } } } } @Preview(showSystemUi = true) @Composable fun DefaultPreview() { MaterialTheme { MyButton() } } @Composable fun MyButton() { Column( modifier = Modifier .fillMaxWidth() .fillMaxHeight(), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { val context = LocalContext.current Button( onClick = { Toast.makeText(context, "Welcome to Geeks for Geeks", Toast.LENGTH_LONG).show() }, modifier = Modifier.padding(16.dp), enabled = true, shape = RoundedCornerShape(12.dp), colors = ButtonDefaults.buttonColors( contentColor = Color.Green, containerColor = Color.Black ), elevation = ButtonDefaults.buttonElevation(defaultElevation = 10.dp), border = BorderStroke(width = 2.dp, brush = SolidColor(Color.Green)), contentPadding = PaddingValues( start = 20.dp, top = 12.dp, end = 20.dp, bottom = 12.dp ), interactionSource = remember { MutableInteractionSource() } ) { Text( text = "Geeks for Geeks", fontSize = 16.sp, fontWeight = FontWeight.Bold, fontStyle = FontStyle.Italic, fontFamily = FontFamily.Serif ) } } } Output: Comment More infoAdvertise with us Next Article Button in Android using Jetpack Compose C chaitanyamunje Follow Improve Article Tags : Technical Scripter Kotlin Android Technical Scripter 2020 Android-Jetpack +1 More Similar Reads Switch Button in Android using Jetpack Compose A Switch or a Switch Button in Android is a UI element that is used to switch between two states upon click. It can be assumed as a Boolean button with two different values. Some states where you may find a Switch in your Android device can be WIFI ON and OFF, Bluetooth ON and OFF, Dark Mode and Lig 2 min read Checkbox in Android using Jetpack Compose The checkbox is a composable function that is used to represent two states of any item in Android. It is used to differentiate an item from the list of items. In this article, we will take a look at the implementation of Simple Checkbox in Android using Jetpack Compose. Attributes of CheckboxAttribu 2 min read Icon Toggle Button in Android using Jetpack Compose Toggle Buttons are used in most applications. These buttons are used to perform multiple operations. Toggle buttons are seen used in many social media applications such as Instagram. In social media apps, we can get to see a heart icon that is used to like the image. We can also unlike that image by 3 min read Change Button Size in Android Jetpack Compose In Android, Button is a very common UI element that is used to call a function or perform a task when clicked by the user. A Button by default occupies specific space depending upon the text that it displays. If the Button text is longer or has a larger font size, the Button width, and height increa 3 min read Motion Layout Button in Android Jetpack Compose Motion Layout is a special version of Constraint layout. With the help of motion layout, we can add animations to the widgets within the layout and change the position of that widget dynamically. In this article, we will take a look at How to implement Motion Layout animation on buttons in Android u 8 min read Like