2

How can I change the color of a horizontal progress bar programmatically without creating a custom drawable?

I tried using this code from another question

progressBar.getProgressDrawable().setColorFilter(Color.RED, Mode.SRC_IN);

but that does not fix it, as the entire progress bar goes red. In the comments there was one user saying to use Mode.MULTIPLY but the entire progress bar just goes black. I also tried using SRC_ATOPwithout success.

My ProgressBar is defined as follows:

<ProgressBar
    android:id="@+id/progress_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="?android:attr/progressBarStyleHorizontal" />

Is there any other way to solve this without using custom drawables?

qwertz
  • 6,206
  • 9
  • 40
  • 62

1 Answers1

-1

android:attr/progressBarStyleHorizontal contains a drawable ; create a drawable it described;

tiny sunlight
  • 6,231
  • 3
  • 21
  • 42