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
  • DSA Tutorial
  • Data Structures
  • Algorithms
  • Array
  • Strings
  • Linked List
  • Stack
  • Queue
  • Tree
  • Graph
  • Searching
  • Sorting
  • Recursion
  • Dynamic Programming
  • Binary Tree
  • Binary Search Tree
  • Heap
  • Hashing
  • Divide & Conquer
  • Mathematical
  • Geometric
  • Bitwise
  • Greedy
  • Backtracking
  • Branch and Bound
  • Matrix
  • Pattern Searching
  • Randomized
Open In App
Next Article:
How to add ColorSeekBar in Android
Next article icon

How to add ColorSeekBar in Android

Last Updated : 12 Sep, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report
Seekbar is a type of progress bar. We can drag the seekbar from left to right and vice versa and hence changes the current progress. ColorSeekbar is similar to seekbar but we use this to select a color from multiple colors and can select any custom color. With the help of this widget, we can give more control to the user to customize its application according to his need. Approach:
  1. Add the support Library in your root build.gradle file (not your module build.gradle file). This library jitpack is a novel package repository. It is made for JVM so that any library which is present in github and bigbucket can be directly used in the application. XML
    allprojects {     repositories {         maven { url "https://jitpack.io" }     } } 
  2. Add the support Library in build.gradle file and add dependency in the dependencies section. This library provides various inbuilt function which we can use to give users maximum independence to customize. XML
    dependencies {     implementation 'com.github.rtugeek:colorseekbar:1.7.7' } 
  3. Now add a array of colors, custom_colors in strings.xml file in values directory. strings.xml
    <array name="custom_colors">              <item>#219806</item>             <item>#F44336</item>             <item>#FFEB3B</item>  </array> 
  4. Now add the following code in the activity_main.xml file.This will add a textview and a colorSeekbar in activity_main. In this file we add our array, custom_colors to the Seekbar. activity_main.xml
    <?xml version="1.0" encoding="utf-8"?> <LinearLayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:gravity="center"     android:orientation="vertical"     android:padding="16dp"     tools:context=".MainActivity">      <TextView         android:id="@+id/text_view"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="GeeksForGeeks"         android:textSize="30sp"         android:textStyle="bold" />      <com.rtugeek.android.colorseekbar.ColorSeekBar         android:id="@+id/color_seek_bar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         app:colorSeeds="@array/custom_colors"         app:showAlphaBar="true" />  </LinearLayout> 
  5. Now add the following code in the MainActivity.java file. onClickListener is added with the seekbar. As the value is changes via seekbar the onClickListener is invoked and color of texts in textview changes. MainActivity.java
    package org.geeksforgeeks.colorseekbar;  import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import com.rtugeek.android.colorseekbar.ColorSeekBar;  public class MainActivity     extends AppCompatActivity {      TextView textView;      @Override     protected void onCreate(         Bundle savedInstanceState)     {          super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          textView = findViewById(             R.id.text_view);         ColorSeekBar             colorSeekBar             = findViewById(                 R.id.color_seek_bar);          colorSeekBar.setOnColorChangeListener(             new ColorSeekBa                 r.OnColorChangeListener() {                      @Override                     public void                     onColorChangeListener(                         int i, int i1, int i2)                     {                         textView                             .setTextColor(i2);                     }                 });     } } 
Output:

Next Article
How to add ColorSeekBar in Android

M

madhavmaheshwarimm20
Improve
Article Tags :
  • Java
  • Android
  • DSA
  • Android-Bars
Practice Tags :
  • Java

Similar Reads

    How to Create a BarChart in Android?
    If you are looking for a UI component to represent a huge form of data in easily readable formats then you can think of displaying this huge data in the form of bar charts or bar graphs. It makes it easy to analyze and read the data with the help of bar graphs. In this article, we will take a look a
    5 min read
    How to Generate Barcode in Android?
    Barcodes are the graphical representation of data that enables effortless scanning. When we aim to incorporate this functionality for various purposes in Android applications it becomes crucial to understand the underlying principles and techniques involved in generating barcodes effectively. In thi
    3 min read
    How to Add RangeSeekbar in Android Using Kotlin?
    In this article,  RangeSeekbar is implemented in an application in android. Android Seekbar is a type of progress bar. We can drag the seekbar from left to right and vice versa and hence changes the current progress. Here we use the RangeSeekbar library to add custom seekbar in our app. This library
    2 min read
    How to Add Florent LongShadow to Android App?
    LongShadow is an Android library that allows us to easily a long shadow to different views in Android Studio. We can use long shadows to make the app more attractive and engaging. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to impl
    3 min read
    How to Create a Paint Application in Android?
    We all have once used the MS-Paint in our childhood, and when the system was shifted from desks to our palms, we started doodling on Instagram Stories, Hike, WhatsApp, and many more such apps. But have you ever thought about how these functionalities were brought to life? So, In this article, we wil
    8 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