SetProgressDrawable fills the entire seekBar

As I said in the title, when I use setProgressDrawable, it fills the entire SeekBar: if progress has reached 34%, progress shows 100%, but the thumb shows the correct percentage 34%. I do not understand what could 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!

+6
source share
4 answers

try placing a fill shape inside the clip tag, for example

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

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

Wherever you use the code to change the pull-out code, simply do the following (where "p" is your search drum):

 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 remember to add the following check in the onProgressChanged Method:

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

example

+3
source

I ended up in the same situation as you and was able to solve the problem by making progress with the XML file at the layer level. See my answer here .

+1
source

You can customize the progressTint field in your xml layout to change the color of progress without affecting the entire SeekBar background.

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

There are also thumbTint and progressBackgroundTint .

0
source

Source: https://habr.com/ru/post/913240/


All Articles