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 Decorators in Python In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are 10 min read Sliding Window Technique Sliding Window Technique is a method used to solve problems that involve subarray or substring or window. The main idea is to use the results of previous window to do computations for the next window. This technique is commonly used in algorithms like finding subarrays with a specific sum, finding t 13 min read AVL Tree Data Structure An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. Example of an AVL Tree:The balance factors for different nodes are : 12 :1, 8:1, 18:1, 5:1, 11:0, 17:0 and 4:0. Since all differences 4 min read What is a Neural Network? Neural networks are machine learning models that mimic the complex functions of the human brain. These models consist of interconnected nodes or neurons that process data, learn patterns, and enable tasks such as pattern recognition and decision-making.In this article, we will explore the fundamenta 14 min read ArrayList in Java Java ArrayList is a part of the collections framework and it is a class of java.util package. It provides us with dynamic-sized arrays in Java. The main advantage of ArrayList is that, unlike normal arrays, we don't need to mention the size when creating ArrayList. It automatically adjusts its capac 9 min read Read JSON file using Python The full form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the JSON package in Pytho 4 min read Multithreading in Python This article covers the basics of multithreading in Python programming language. Just like multiprocessing , multithreading is a way of achieving multitasking. In multithreading, the concept of threads is used. Let us first understand the concept of thread in computer architecture. What is a Process 8 min read Two Pointers Technique Two pointers is really an easy and effective technique that is typically used for Two Sum in Sorted Arrays, Closest Two Sum, Three Sum, Four Sum, Trapping Rain Water and many other popular interview questions. Given a sorted array arr (sorted in ascending order) and a target, find if there exists an 11 min read Python Match Case Statement Introduced in Python 3.10, the match case statement offers a powerful mechanism for pattern matching in Python. It allows us to perform more expressive and readable conditional checks. Unlike traditional if-elif-else chains, which can become unwieldy with complex conditions, the match-case statement 7 min read Architecture of 8085 microprocessor A microprocessor is fabricated on a single integrated circuit (IC) or chip that is used as a central processing unit (CPU).The 8085 microprocessor is an 8-bit microprocessor that was developed by Intel in the mid-1970s. It was widely used in the early days of personal computing and was a popular cho 11 min read Like