Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add two colors in progress bar in android?

I am trying to add two colors in progress bar. in my project there is a button called "increase". When I press increase and holds it then the progress bar increases with yellow color, now what I am trying is that when I release "increase" button the progress bar should add a small bar with green color.

My problem is that when I release the button then whole progress bar is getting filled by green color instead of yellow color till I hold the button and a small bar at releasing the button.

I am attaching the screenshot.

enter image description here

below is the code snippet

if (i == 0) {
   progressBar1.setProgress(progressBar1.getProgress() + 10);
   progressBar1.setProgressDrawable(getResources().getDrawable(
     R.drawable.progress_layer));
   i = 1;
  } else {
   progressBar1.setProgress(progressBar1.getProgress() + 1);
   progressBar1.setProgressDrawable(getResources().getDrawable(
     R.drawable.progress_layer_normal));
  }

Here i is 0 by default when I tap and holds the button progress bar increase with yellow color. now when I release the button i becomes 1 and green color bar should be added to the progress bar. but the whole progress bar becomes green.

enter image description here

like image 965
rahul Avatar asked Nov 11 '22 13:11

rahul


1 Answers

It is impossible to achieve that with the standard ProgressBar. You should consider creating the custom view from scratch.
You can start here

like image 127
Alex Avatar answered Nov 14 '22 21:11

Alex