Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
Checkbox in Android using Jetpack Compose
Next article icon

Checkbox in Android using Jetpack Compose

Last Updated : 28 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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 Checkbox

Attributes

Uses

checked this is used to set our checkbox checked or unchecked on app launch.
onCheckedChange this is a callback that will receive when there is a change in events whether the checkbox is checked or unchecked.
modifier this is used to add beautification to our checkbox in the sense of padding, margin, and other properties. 
color this parameter is used to add color to our checkbox in the default case the checkbox color is a secondary color in the app theme.

enabled

this parameter is used to add a boolean value that determines whether the checkbox is enabled.

interactionSource

this parameter uses an interaction source that handles interaction events for the checkbox.

Step-by-Step Implementation

Step 1: Create a New Project

To create a new project in the Android Studio please refer to How to Create a new Project in Android Studio with Jetpack Compose.

Step 2: Working with the MainActivity.kt file

Navigate to the app > java > {package name} > MainActivity.kt file. Inside that file add the below code to it. Comments are added inside the code to help you understand the code in more detail.

MainActivity.kt:

Kotlin
package com.geeksforgeeks.demo  import android.os.Bundle import androidx.activity.* import androidx.activity.compose.setContent import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.* import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp  class MainActivity : ComponentActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         enableEdgeToEdge()         setContent {             Column {                 Component()             }         }     } }  @Composable fun Component() {     // set the state of our checkbox.     val isChecked = remember { mutableStateOf(false) }      // creating a checkbox in a Column.     Column(         modifier = Modifier             .fillMaxWidth()             .fillMaxHeight()             .padding(16.dp),         verticalArrangement = Arrangement.Center,         horizontalAlignment = Alignment.CenterHorizontally     ) {         Checkbox(             // set the state of checkbox.             checked = isChecked.value,             onCheckedChange = { isChecked.value = it },             modifier = Modifier.padding(8.dp),             enabled = true,             colors = CheckboxDefaults.colors(                 checkedColor = Color.Green,                 uncheckedColor = Color.DarkGray,                 checkmarkColor = Color.White             ),             interactionSource = remember { MutableInteractionSource() }         )         Text(             text = if (isChecked.value) "Checked" else "Unchecked",             modifier = Modifier.padding(top = 8.dp)         )     } } 

Output:


Next Article
Checkbox in Android using Jetpack Compose

C

chaitanyamunje
Improve
Article Tags :
  • Technical Scripter
  • Kotlin
  • Android
  • Technical Scripter 2020
  • Android-Jetpack

Similar Reads

    Button in Android using Jetpack Compose
    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 a
    3 min read
    Text Clock in Android using Jetpack Compose
    Text Clock is a UI widget in android which is used to display the current time in android applications. This widget displays the current time in a simple text view. The text clock widget displays a time in 12 and 24 hours format. In this article, we will take a look at How to use the TextClock widge
    2 min read
    Text in Android using Jetpack Compose
    Jetpack Compose is a new toolkit provided by Google. This is useful for designing beautiful UI designs. Android Text is a simple view in Android which is used to display text inside our App. In this article, we will take a look at the implementation of Text in Android using Jetpack Compose. Importan
    5 min read
    Custom Chips using Jetpack Compose in Android
    Chips in android are one of the components which are used to make the choice filters, actions, and display the selectable options in the compact area of the Android Window. In this article, we will use Android's Jetpack Compose to create those chips. A sample image is given below to give an idea of
    5 min read
    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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences