How to change default color of progress bar?

2019-01-13 16:16发布

I am using a circular ProgressBar in my Activty.My Problem is this it is not visible properly on my page because my page's BG color is same as ProgressBar .So how can I change the color of ProgressBar to make it properly Visible? Please Help

10条回答
forever°为你锁心
2楼-- · 2019-01-13 16:42

you also can change only the attribute

android:indeterminateDrawable="@drawable/yourxmlfile"

and keep this style

style="@android:style/Widget.ProgressBar.Small"
查看更多
Summer. ? 凉城
3楼-- · 2019-01-13 16:46

Please make one xml file name progress.xml and put it in res/xml folder and write the below code in that xml file.

 <?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
    android:toDegrees="360">
    <shape android:shape="ring" android:innerRadiusRatio="3"
        android:thicknessRatio="8" android:useLevel="false">

        <size android:width="76dip" android:height="76dip" />
        <gradient android:type="sweep" android:useLevel="false"
            android:startColor="#447a29" 
            android:endColor="#447a29"
            android:angle="0"
             />
    </shape>
</rotate> 

after creating this xml file set your progressbars background as this xml ..

Like

<ProgressBar
  android:id="@+id/ProgressBar01" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background = "@xml/progress">
查看更多
你好瞎i
4楼-- · 2019-01-13 16:48

here is how you can do it by java code.

progressBar.getProgressDrawable().setColorFilter(ContextCompat.getColor(getActivity(),R.color.product_status_color), PorterDuff.Mode.MULTIPLY)
查看更多
你好瞎i
5楼-- · 2019-01-13 16:50

Here is some explanation. For changing background of a Indeterminate ProgressBar, you need a rotating ring because it rotates. In the answer of @Chirag, he has defined a rotating ring and applied it to the background of ProgressBar. If you have a Horizontal ProgressBar then you need a rectangle.

PS: I have not tried with other shapes.

查看更多
戒情不戒烟
6楼-- · 2019-01-13 16:50

in xml u can apply color like this

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/loader"
    android:indeterminateTint="@color/my_color"
    android:layout_centerInParent="true"/>
查看更多
时光不老,我们不散
7楼-- · 2019-01-13 16:51

create progress drawable file

<?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" />
        <solid android:color="@color/colorWhite" />
    </shape>
</item>

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

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

and set android:progressDrawable="@drawable/app_progressbar_back"

like this

<ProgressBar
                android:id="@+id/dialogProgressView"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:progressDrawable="@drawable/app_progressbar_back"
                android:progress="50"
                android:layout_marginTop="@dimen/margin_20" />
查看更多
登录 后发表回答