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:
Color Picker in Android using Jetpack Compose
Next article icon

Color Picker in Android using Jetpack Compose

Last Updated : 16 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Color Picker is seen in many paint applications and is used for drawing some components and coloring them. In these applications, we can get to see different color pickers which are used to pick the color and paint that specific component. In this article, we will take a look at How to implement Color Picker in Android using Jetpack Compose. A sample video is given below to get an idea about what we are going to do in this article.

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.

Step 2: Adding dependency in build.gradle file

Navigate to app > build.gradle and add the below dependency in the dependencies section.

implementation "com.github.skydoves:colorpicker-compose:1.0.0"

Now sync your project to install the dependency within the android application.

Step 3: Adding a new color to the Color.kt file

Navigate to app > java > your app’s package name > ui.theme > Color.kt file and add the below code to it. 

Kotlin
package com.example.newcanaryproject.ui.theme  import androidx.compose.ui.graphics.Color  val Purple200 = Color(0xFF0F9D58) val Purple500 = Color(0xFF0F9D58) val Purple700 = Color(0xFF3700B3) val Teal200 = Color(0xFF03DAC5)  // on below line we are adding different colors. val greenColor = Color(0xFF0F9D58) 

Step 4: Working with the MainActivity.kt file

Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.

Kotlin
package com.example.newcanaryproject  import android.app.Activity import android.content.Context import android.net.Uri import android.os.Bundle import android.util.DisplayMetrics import android.util.Log import android.view.WindowManager import android.widget.Chronometer import android.widget.MediaController import android.widget.Toast import android.widget.VideoView import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.* import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.imageResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.* import com.example.newcanaryproject.ui.theme.* import com.github.skydoves.colorpicker.compose.* import dev.shreyaspatil.easyupipayment.EasyUpiPayment import dev.shreyaspatil.easyupipayment.listener.PaymentStatusListener import dev.shreyaspatil.easyupipayment.model.PaymentApp import dev.shreyaspatil.easyupipayment.model.TransactionDetails import java.text.SimpleDateFormat import java.util.*  class MainActivity : ComponentActivity() {      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContent {             NewCanaryProjectTheme {                 // on below line we are specifying background color for our application                 Surface(                     // on below line we are specifying modifier and color for our app                     modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background                 ) {                      // on the below line we are specifying the theme as the scaffold.                     Scaffold(                          // in scaffold we are specifying the top bar.                         topBar = {                              // inside top bar we are specifying background color.                             TopAppBar(backgroundColor = greenColor,                                  // along with that we are specifying title for our top bar.                                 title = {                                      // in the top bar we are specifying tile as a text                                     Text(                                          // on below line we are specifying                                         // text to display in top app bar.                                         text = "GFG",                                          // on below line we are specifying                                         // modifier to fill max width.                                         modifier = Modifier.fillMaxWidth(),                                          // on below line we are specifying                                         // text alignment.                                         textAlign = TextAlign.Center,                                          // on below line we are specifying                                         // color for our text.                                         color = Color.White                                     )                                 })                         }) {                         // on below line we are                            // calling color picker method                          colorPicker()                     }                 }             }         }     } }  @Composable fun colorPicker() {     // on below line we are creating a variable for controller     val controller = rememberColorPickerController()      // on below line we are creating a column,     Column(         // on below line we are adding a modifier to it,         modifier = Modifier             .fillMaxSize()             // on below line we are adding a padding.             .padding(all = 30.dp)     ) {         // on below line we are adding a row.         Row(             // on below line we are adding a modifier             modifier = Modifier.fillMaxWidth(),             // on below line we are adding horizontal               // and vertical alignment.             horizontalArrangement = Arrangement.Center,             verticalAlignment = Alignment.CenterVertically         ) {             // on below line we are adding a alpha tile.             AlphaTile(                 // on below line we are                    // adding modifier to it                 modifier = Modifier                     .fillMaxWidth()                     // on below line                        // we are adding a height.                     .height(60.dp)                     // on below line we are adding clip.                     .clip(RoundedCornerShape(6.dp)),                 // on below line we are adding controller.                 controller = controller             )         }         // on below line we are            // adding horizontal color picker.         HsvColorPicker(             // on below line we are               // adding a modifier to it             modifier = Modifier                 .fillMaxWidth()                 .height(450.dp)                 .padding(10.dp),             // on below line we are                // adding a controller             controller = controller,             // on below line we are                // adding on color changed.             onColorChanged = {}         )         // on below line we are adding a alpha slider.         AlphaSlider(             // on below line we                // are adding a modifier to it.             modifier = Modifier                 .fillMaxWidth()                 .padding(10.dp)                 .height(35.dp),             // on below line we are                // adding a controller.             controller = controller,             // on below line we are                // adding odd and even color.             tileOddColor = Color.White,             tileEvenColor = Color.Black         )         // on below line we are            // adding a brightness slider.         BrightnessSlider(             // on below line we               // are adding a modifier to it.             modifier = Modifier                 .fillMaxWidth()                 .padding(10.dp)                 .height(35.dp),             // on below line we are               // adding a controller.             controller = controller,         )     } } 

Now run your application to see the output of it. 

Output:


Next Article
Color Picker in Android using Jetpack Compose

C

chaitanyamunje
Improve
Article Tags :
  • Kotlin
  • Android
  • Android-Jetpack

Similar Reads

    Image Color Picker in Android using Jetpack Compose
    Many android applications require functionality in which the user should be able to pick the color from the image which is present within the android application. In this article, we will take a look at How to implement Image Color Picker in Android applications using Jetpack Compose. We will be abl
    5 min read
    Pie Chart in Android using Jetpack Compose
    Pie Charts are used in many Android applications to display a huge quantity of data in a simple and easy format. This is seen in applications where a huge quantity of data is to be handled. In this article, we will take a look at How to Create a Pie Chart in Android using Jetpack Compose. A sample v
    7 min read
    Date Picker in Android using Jetpack Compose
    In Android, a Date Picker is a widget used to select a date from the calendar. When a Date Picker is implemented in an application, the user can select a year, a month, and a day, combining to form date from a calendar-like-looking box. This data is generally needed and collected in applications tha
    2 min read
    Time Picker in Android using Jetpack Compose
    In Android, a Time Picker is a modern UI element, used in applications like Alarm and Reminders, that requires users to select a particular time for performing a particular task. It is a user interface control for selecting the time in either 24-hour format or 12-hour (AM/PM) mode. In this article,
    3 min read
    Contact Picker in Android using Jetpack Compose
    Many applications require a functionality where users can pick a specific contact from their contact list and display that contact within the android application to perform some action on that contact such as sending an SMS or making a call. In this article, we will take a look at How to create a co
    6 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