23

i want to change Horizontal ProgressBar color

i have tried this

How to change the color of an indefinite ProgressBar?

its not working still progress run in blue color

this is my code

<ProgressBar
                 android:id="@+id/mini_progress"
                 android:layout_marginLeft="10dip"
                 android:layout_marginRight="10dip"
                 style="?android:attr/progressBarStyleHorizontal"
                 android:layout_width="match_parent"
                 android:layout_height="20dip"
                 android:layout_gravity="center_horizontal"
                 android:indeterminate="false"
                 android:indeterminateBehavior="repeat"
                 android:indeterminateOnly="true"
                 android:visibility="gone"/>

how i can change the color to Pink ?

Community
  • 1
  • 1
Noob
  • 2,857
  • 6
  • 33
  • 47

6 Answers6

33

Try this code -

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="5dip" />

                <solid android:color="#f58233" />
            </shape>
        </clip>

        <color android:color="#f58233" />
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />

                <solid android:color="#f58233" />
            </shape>
        </clip>

        <color android:color="#f58233" />
    </item>

</layer-list>

Progress Bar -

<ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="200dp"
            android:layout_height="3dip"
            android:progressDrawable="@drawable/progress_bar" />

Change color codes according to your need

Vishal Pawale
  • 3,416
  • 3
  • 28
  • 32
14

I did this to get the required color :

    android:indeterminate="true"
    android:indeterminateTintMode="src_atop"
    android:indeterminateTint="@color/myColor"

Works perfectly for me.(API 21 or higher)

mamzi
  • 495
  • 5
  • 11
arqam
  • 3,582
  • 5
  • 34
  • 69
12

For me this worked well.

enter image description here

<ProgressBar
            android:id="@+id/verify_progress"
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:layout_below="@id/verify_phone"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:indeterminate="false"
            android:progressDrawable="@drawable/progress_bar" </ProgressBar>

drawable/progress_bar -

  <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:id="@android:id/background">
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:startColor="@color/Gray"
                    android:centerColor="@color/Gray"
                    android:endColor="@color/Gray"
                    />
            </shape>
        </item>


        <item
            android:id="@android:id/progress"
            >
            <clip>
                <shape>
                    <corners
                        android:radius="5dip" />
                    <gradient
                        android:startColor="@color/PrimaryColor"
                        android:endColor="@color/PrimaryColor" />
                </shape>
            </clip>
        </item>

    </layer-list>
Vikram
  • 768
  • 2
  • 9
  • 23
3

Since API 21 it's a one liner:

<ProgressBar
            ...
            android:progressTint="@color/colorAccent"/>
Javatar
  • 2,518
  • 1
  • 31
  • 43
0

Add a renderer:

public class CustomProgressBarRenderer :ProgressBarRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ProgressBar> e)
    {
        base.OnElementChanged(e);

        Control.ProgressDrawable.SetColorFilter(Color.FromRgb(182, 231, 233).ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcIn);
        //Control.ProgressTintListColor.FromRgb(182, 231, 233).ToAndroid();
        Control.ProgressTintList = Android.Content.Res.ColorStateList.ValueOf(Color.FromRgb(182, 231, 233).ToAndroid());


    }
}
KaeM
  • 225
  • 3
  • 6
0

this works on pre-lollipop devices.

progressBar.getProgressDrawable().setColorFilter(ContextCompat.getColor(getActivity(),R.color.product_status_color), PorterDuff.Mode.MULTIPLY)
vikas kumar
  • 10,447
  • 2
  • 46
  • 52