Button in Android using Jetpack Compose Last Updated : 23 Jul, 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 C chaitanyamunje Follow Improve Article Tags : Android Technical Scripter 2020 Android-Jetpack Explore Android Tutorial 15+ min read BasicsIntroduction to Android Development 5 min read History of Android 15+ min read Best Way to Become Android Developer â A Complete Roadmap 7 min read Android Development Prerequisites [2025] - Things to Learn Before Android Development 8 min read Android App Development Fundamentals for Beginners 6 min read Android Architecture 5 min read Android System Architecture 3 min read Android Boot Process 4 min read Difference between Java and Kotlin in Android with Examples 3 min read Interesting Facts About Android 3 min read Software Setup and ConfigurationDownload and Instal JDK on Windows, Mac and Linux 7 min read Guide to Install and Setup IntelliJ IDEA for Android App Development 5 min read Guide to Install and Setup Visual Studio for Android App Development 4 min read How to Run the Android App on a Real Device? 2 min read Resolving frequently occurring errors in Android Development 3 min read Android Studio Tutorial 9 min read File Structure & ComponentsComponents of an Android Application 3 min read Introduction to Activities in Android 6 min read Services in Android with Example 10 min read Core TopicsHow Does Android App Work? 7 min read Activity Lifecycle in Android with Demo App 9 min read Introduction to Gradle 4 min read What is Context in Android? 9 min read Bundle in Android with Example 6 min read Activity State Changes In Android with Example 6 min read Processes and Application Lifecycle in Android 7 min read Desugaring in Android 4 min read Difference Between AndroidX and Android Support Libraries 3 min read Memory Leaks in Android 7 min read Layout & ViewLayouts in Android UI Design 3 min read Android UI Layouts 5 min read LinearLayout and its Important Attributes with Examples in Android 3 min read Android LinearLayout in Kotlin 2 min read Android RelativeLayout in Kotlin 4 min read ConstraintLayout in Android 6 min read TextView widget in Android with Examples 5 min read TextView in Kotlin 3 min read Working With the TextView in Android 7 min read Autosizing TextView in Android 6 min read ButtonButton in Android 3 min read How to Add Radio Buttons in an Android Application? 5 min read RadioButton in Kotlin 4 min read How to add Toggle Button in an Android Application 3 min read ToggleButton in Kotlin 2 min read RadioGroup in Kotlin 3 min read Intent and Intent FiltersWhat is Intent in Android? 4 min read Implicit and Explicit Intents in Android with Examples 6 min read How to Send Data From One Activity to Second Activity in Android? 7 min read How to open dialer in Android through Intent? 3 min read Creating Multiple Screen Applications in Android 6 min read How to Open Camera Through Intent and Display Captured Image in Android? 6 min read Toast & RecyclerViewToasts for Android Studio 2 min read What is Toast and How to Use it in Android with Examples? 6 min read Android Toast in Kotlin 3 min read How to Change Toast font in Android? 3 min read How to add a custom styled Toast in Android 4 min read RecyclerView in Android with Example 7 min read Android | Horizontal RecyclerView with Examples 4 min read How to create a nested RecyclerView in Android 5 min read How to Create RecyclerView with Multiple ViewType in Android? 6 min read RecyclerView using ListView in Android With Example 5 min read Like