Reputation: 265
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
Upvotes: 1
Views: 1660
Reputation: 457
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.
Upvotes: 2
Reputation: 105
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,..
Upvotes: 0
Reputation: 7749
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: mProgressTintList
and 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.
Upvotes: 0