[SOLVED] I cannot change the progressbar's progress when i am setting progressbar max and min value

Issue

How to change the progressbar’s progress color when you have set max and min value of progressbar. i have a progressbar and try to set max value as 15 and min value as -5. i want to show progress from -5 to 0 as progress and change the color of progress as red and show green color as 0 to 15 to the progressbar.

    <style name="CustomProgressBarReturnRange" parent="android:Widget.ProgressBar.Horizontal">
        <item name="android:indeterminateOnly">false</item>
        <item name="android:minHeight">4dp</item>
        <item name="android:maxHeight">4dp</item>
    </style>

   <ProgressBar
        android:id="@+id/returnProgress"
        style="@style/CustomProgressBarReturnRange"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="15"
        android:min="-5"
        android:progress="0" 
        tools:progress="20" />

Solution

  <style name="CustomProgressBarReturnRange" parent="android:Widget.ProgressBar.Horizontal">
        <item name="android:indeterminateOnly">false</item>
        <item name="android:progressDrawable">@drawable/custom_return_range_progress</item>
        <item name="android:minHeight">4dp</item>
        <item name="android:maxHeight">4dp</item>
    </style>

<ProgressBar
       android:id="@+id/returnProgress"
       style="@style/CustomProgressBarReturnRange"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:max="15"
       android:min="-5"
       android:progress="0" />


if (progressBar.progress <= 0) 
{
  progressBar.progressTintList = ColorStateList.valueOf(Color.RED)
} 
else if (progressBar.progress > 0)
{
  progressBar.progressTintList = ColorStateList.valueOf(Color.WHITE)
}

Answered By – rNkL

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published.