Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Android SeekBar to draw secondary progress on top of primary progress?

I would like to change the behavior of an android seekbar so that the secondary android seekbar is actually drawn on top of the primary android seekbar. From the ProgressBar documentation listed here: http://developer.android.com/reference/android/widget/ProgressBar.html#attr_android:secondaryProgress

This progress is drawn between the primary progress and the background.

Current look of secondary Progress bar:

Default secondary progress bar

Desired look of secondary progress bar:

Desired secondary progress bar

Ideally I'd like to override a method in ProgressBar.java in Android to change the order of drawing so that the secondary progress bar is drawn on top of the primary progress bar, but I've had difficulty finding the proper area in the source code to override. Any ideas where to look?

I have had success attempting to draw two progress bars one on top of another using a relative layout, but this approach requires creating two controls.

like image 692
CrimsonX Avatar asked Jan 31 '26 07:01

CrimsonX


1 Answers

This is a late answer, but just I found out how to do this. Not that difficult :)

First of all look at how the progress drawable is defined in the android project [here].(https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable/progress_horizontal_holo_dark.xml)

All you have to do is switch the order of secondaryProgress and progress so that progress comes before (lies below) secondaryProgress like this:

<item android:id="@android:id/background"
      android:drawable="@android:drawable/progress_bg_holo_dark" />

<item android:id="@android:id/progress">
    <scale android:scaleWidth="100%"
           android:drawable="@android:drawable/progress_primary_holo_dark" />
</item>

<item android:id="@android:id/secondaryProgress">
    <scale android:scaleWidth="100%"
           android:drawable="@android:drawable/progress_secondary_holo_dark" />
</item>

Now sadly those resources are not public. So you will have to copy progress_bg_holo_dark.9.png, progress_primary_holo_dark.9.png and progress_secondary_holo_dark.9.png to your projects drawable-xhdpi folder (and maybe to the same with other dpi images as well).

Then adjust the xml file like the following (just remove "android:"):

<item android:id="@android:id/background"
      android:drawable="@drawable/progress_bg_holo_dark" />

<item android:id="@android:id/progress">
    <scale android:scaleWidth="100%"
           android:drawable="@drawable/progress_primary_holo_dark" />
</item>

<item android:id="@android:id/secondaryProgress">
    <scale android:scaleWidth="100%"
           android:drawable="@drawable/progress_secondary_holo_dark" />
</item>

like image 106
Patrick Boos Avatar answered Feb 01 '26 22:02

Patrick Boos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!