How to make colored SeekBar in Android

Here i am going to use ColorSeekBar Library to make different color based seekbar

Follow all these steps to make colored seedbar in Android

  • Add the JitPack repository in your root build.gradle at the end of repositories
allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}
  • Add the dependency
implementation 'com.github.rtugeek:colorseekbar:2.0.3'

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="tech.codingpoint.colorseekbarexample.MainActivity">

    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        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>

arrays.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="custom_colors">
        <item>#F44336</item>
        <item>#8BC34A</item>
        <item>#FFEB3B</item>
    </array>
</resources>

MainActivity.java

package tech.codingpoint.colorseekbarexample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.rtugeek.android.colorseekbar.ColorSeekBar;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final TextView textView = findViewById(R.id.text_view);
        ColorSeekBar colorSeekBar = findViewById(R.id.color_seek_bar);

        colorSeekBar.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() {
            @Override
            public void onColorChangeListener(int i, int i1, int i2) {
                textView.setTextColor(i2);
            }
        });
    }
}

Leave a Comment