1

I want to change the colors of a ProgressBar in Android only programmatically. My problem is, how can I set a different color for the progress and another color for the "to fill" - part of the progress bar

Example:

  • Progress should be green

  • Last part should be red

it should look like this

Arlind Hajredinaj
  • 8,380
  • 3
  • 30
  • 45
kimbl
  • 265
  • 1
  • 2
  • 12

3 Answers3

2

There is no possibility to do that atm. You have to develop your own custom view for achieving this.

Create a custom view, extending a Layout, and use the layout for your background of the progress bar. Add another view (starting with 0dp width) for your growing progress.

Add a public method for setting the current progress and adjust the width of the progress view.

Fabian Köbel
  • 457
  • 1
  • 7
  • 21
0

You can't apply a custom Style to a Progressbar with the official API.

You might be able to do it using reflection though. A Progressbar has a private field mProgressTintInfo which has following fields: mProgressTintListand mProgressBackgroundTintList, which are ColorStateLists and mHasProgressTint and mHasProgressBackgroundTint, which are booleans.

I've never tried this myself, it might not work at all or only work on specific API levels / devices.

F43nd1r
  • 7,690
  • 3
  • 24
  • 62
0

Sorry for my english, i speak spanish yo can implement you own progressbar, and override the method "ondraw" and uses 2 filled rectangles and a 2 filled circles with yours own colors.

again, super sorry for my english,..

Enzo
  • 95
  • 1
  • 5