6

As I say in the title, when I use setProgressDrawable, it fills the entire SeekBar: if progress is at 34%, progress show 100% but thumb shows the correct percentatge 34%. I don't figure out what can be the problem...

   done.setProgressDrawable(getResources().getDrawable(R.drawable.seekbar_progress));
   done.setThumb(getResources().getDrawable(R.drawable.seekbar_thumb));

seekbar_progress.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="15dp"    android:color="#52a8ec"/>

seekbar_thumb.xml

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
<gradient android:startColor="#ffffffff" android:endColor="#ff585858" android:angle="270"/>
<size android:height="17dp" android:width="5dp"/>
</shape>

Any idea?

Thank you in advance!

anonymous
  • 1,320
  • 5
  • 21
  • 37

4 Answers4

8

try to put the fill shape inside a clip tag like so

<clip>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="15dp"    android:color="#52a8ec"/>
</clip>
Dan Levin
  • 718
  • 7
  • 16
  • This fixed the issue for me, thanks, and I think is a better answer as it's all within the custom progress bar XML rather than adding code. – Botman Oct 23 '14 at 01:24
  • This solution worked for me. But I don't know how it works. Please explain to understand better. – Oğuzhan Koşar Feb 14 '18 at 10:00
3

I faced the same problem and the following code resolved it.

Wherever you are using the code to change your drawable just do the following (where 'p' is your seekbar) :

int currentProgress = p.getProgress();
p.setProgress(0);
Rect bounds = p.getProgressDrawable().getBounds();
p.setProgressDrawable(getResources().getDrawable(R.drawable.progress_drawable_orange));
p.getProgressDrawable().setBounds(bounds);
p.setProgress(currentProgress);

and do not forget to add the following check in your onProgressChanged method:

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    if(!fromUser)
        return;
    // ... THE REST OF YOUR CODE
}

example

Gary
  • 13,303
  • 18
  • 49
  • 71
alchemist
  • 1,081
  • 12
  • 17
1

I ended in the same situation as you did and managed to resolve the problem by implementing progress with layer-list XML file. See my answer here.

Community
  • 1
  • 1
Milos Pesic
  • 720
  • 2
  • 8
  • 23
  • I've copyied and pasted all your xml files and it stills filling the entire seekbar... – anonymous May 16 '12 at 12:37
  • Some people suggest that after calling setProgressDrawable() method, SeekBar needs to be redrawn. Try setting the padding, incrementing progress etc. My code afterwards is: seekBar.setThumb(d); seekBar.incrementProgressBy(1); seekBar.setProgress(0); seekBar.setThumbOffset(-1); seekBar.setMax((int) (max - min)); – Milos Pesic May 24 '12 at 11:24
0

You can tweak the progressTint field in your layout xml to change the progress color without affecting the SeekBar's entire background.

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

There's also thumbTint and progressBackgroundTint.

theshadowchild
  • 401
  • 4
  • 6