Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom SeekBar which changes both Progress Color and Background Color while buffering


I want to build a custom SeekBar which has a secondary progress bar but by default is from end to end and shows progress for buffered data.

Think of it as the seekbar provided by most online video players e.g. youtube. So all in all we have the default seekbar, its default progress bar and a secondary progress bar which fills a color irrespective of the main progress/user's drag of the seekbar's notch and just dependent on buffered data.

Till now I just have the normal seekbar and it changes color on user's drag/set progress.
Could someone please help with this?

My code so far:
seekbar_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/progress_background_fill"/>
    <item android:id="@android:id/progress">
        <clip android:drawable="@drawable/progress_fill" />
    </item>

</layer-list>

progress_fill.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <gradient
        android:angle="180"
        android:centerColor="#FFB80000"
        android:endColor="#FFFF4400"
        android:startColor="#FF470000" />

    <corners android:radius="5px" />

    <stroke
        android:width="2dp"
        android:color="#50999999" />
    <stroke
        android:width="1dp"
        android:color="#70555555" />

</shape>

progress_background_fill.xml

<gradient
    android:angle="90"
    android:centerColor="#FF555555"
    android:endColor="#FF555555"
    android:startColor="#FF555555" />

<corners android:radius="5px" />

<stroke
    android:width="2dp"
    android:color="#50999999" />
<stroke
    android:width="1dp"
    android:color="#70555555" />

applying these xml(s) like this:

<SeekBar 
            android:id="@+id/seek_hist_timeline"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:progressDrawable="@drawable/seekbar_progress" />
like image 316
beerBear Avatar asked Jan 31 '14 05:01

beerBear


People also ask

How do I change the color of my SeekBar track?

If you are using default SeekBar provided by android Sdk then their is a simple way to change the color of that . just go to color. xml inside /res/values/colors. xml and change the colorAccent.

How do I change the progress of a SeekBar?

A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys.

What is discrete SeekBar?

In Android Discrete SeekBar is just an advancement of progressBar just like the SeekBar, the only difference in SeekBar and discrete SeekBar being that in discrete SeekBar, we can only set the value only to discrete values like 1, 2, 3, and so on.

What is SeekBar in video?

If you're not familiar with the SeekBar component, it's a component used to seek through media files – you'll likely see one within the media player in your device.


2 Answers

Add another layer to your layer-list drawable with the id android:id/secondaryProgress

Refer to this answer: https://stackoverflow.com/a/2021119/2951003

like image 102
dandc87 Avatar answered Sep 17 '22 22:09

dandc87


Here's your answer. Just add two lines in seekbar tag in xml

<SeekBar
    android:progressTint="@color/black"
    android:thumbTint="@color/black"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

change color accordingly.

like image 41
Nevil Ghelani Avatar answered Sep 18 '22 22:09

Nevil Ghelani