I have custom circle progressbar in Android which I made with drawable circular.xml
Here is my progressbar:
<ProgressBar
android:id="#+id/circle_progress_id"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="40dp"
android:layout_height="40dp"
android:indeterminate="false"
android:max="100"
android:rotation="-90"
android:progressDrawable="#drawable/circular"
android:layout_toRightOf="#id/checkbox_id"
android:background="#drawable/circle_shape"/>
Here is code from #drawable/circular
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:innerRadiusRatio="3.4"
android:shape="ring"
android:thicknessRatio="9.0"
android:useLevel="true" >
<gradient
android:endColor="#4CAF50"
android:startColor="#4CAF50"
android:type="sweep"
android:useLevel="true" />
</shape>
</item>
</selector>
And it works fine and show progress after:
recyclerTaskHolder.progressBarStage.setProgress(getStageProgressValue(myTask));
But it absolutely empty when it is zero progress.
I need to show for user empty gray color progress bar when it is zero progress. Or show empty part of progress bar with gray color when it is between zero and 100%.
I tried to make custom background of progress bar
android:background="#drawable/circle_shape"
Here is circle_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:innerRadiusRatio="3.4"
android:shape="ring"
android:thicknessRatio="9.0"
android:useLevel="true"
android:visible="true">
<gradient
android:endColor="#000000"
android:startColor="#000000"
android:type="sweep"
android:useLevel="true" />
</shape>
</item>
</selector>
But it didn't help me and empty progress bar is still invisible.
Unfortunately I didn't find the reason of this issue.
But I use this library for Circle Progress Bar and it works fine.
CircularProgressBar
It is easy to use this library.
I am using a circular ProgressBar in my Activty.
My Problem is that its color isnt changing properly where only BG color is Changing.
So how can I change the color of ProgressBar without BG.
I tried this thread- How to change default color of progress bar?
http://i.stack.imgur.com/DEpyM.jpg
You can do all in xml files
After some search I got the answer :
you progress bar code :
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="100"
android:indeterminateDrawable="#drawable/progress"
/>
and the progress drawable is consisting of a rotating ring has a gradiant color of your choise like this :
<?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="#007700"
android:endColor="#115511"
android:angle="0"
/>
</shape>
</rotate>
just like this , please rate this answer :)
Better way (using AppCompat libs):
final int color = Color.WHITE; // Or any other one
final ProgressBar progressBar= (ProgressBar) findViewById(R.id.progress_bar);
DrawableCompat.setTint(progressBar.getIndeterminateDrawable(), color);
I want to creat a circular ProgressBar with rounded edge. I have tried CircleProgress library hosted here
https://github.com/lzyzsd/CircleProgress
But the DonutProgress don't have rounded edge which I want. But with my custom progreesDrawable also I am not able to achieve it.
I want to design progress bar as shown below
One corner Rounded as marked in picture.
My custom_progress_bar.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/progress">
<rotate
android:fromDegrees="90"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="15.0" >
<corners
android:radius="5dp"
android:topRightRadius="5dp"
android:topLeftRadius="5dp"
/>
<gradient
android:centerColor="#8AFF00"
android:endColor="#006554"
android:startColor="#006554"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
My layout file
<RootLayout...>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="152dp"
android:layout_height="152dp"
android:layout_centerInParent="true"
android:progress="100"
android:indeterminate="false"
android:progressDrawable="#drawable/back_progress" />
<ProgressBar
android:id="#+id/progressWheel"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="152dp"
android:layout_height="152dp"
android:layout_centerInParent="true"
android:progress="90"
android:indeterminate="false"
android:progressDrawable="#drawable/circular_progress_bar" />
</RootLayout...>
Also I had to use two ProgressBar overlapping each other just to achieve the background thing(grey). I tried defining the background shape too inside my custom_progress_bar.xml but it was not working, so I had to do this. I know its not the solution but I was not able to make it happen by other way.
Can anybody help me to design this progress bar in better way with rounded edge too.
I'm a little late to the party, but the code I added in my fork of castorflex's smoothProgressBar can create the progress bar you are describing! the library already had rounded edge progress bar and a friend and I (shout out to Ryan) were able to get the gradient working with it nicely. https://github.com/alex-sanchez-sd/SmoothProgressBar
When I add horizontal ProgressBar it behaves as expected -- I set the progress value and it shows it.
However when I add ProgressBar (circular) it spins. And that's it. In such form it is more "please wait" indicator, that any progress bar, because progress value is not shown.
So my question is (assuming Progress in name means progress) -- how to stop spinning and shows progress value? For example if I set max to 100, and value to 50 I would expect to see half-circle arc.
In other words how to make circular ProgressBar to behave like horizontal ProgressBar, with only exception of the shape?
I know that this is an old post but I ran into the same issue and I make it work.
It is actually easier than you think, you have to set a custom progress in an xml file inside your drawable folder and handle the attributes "fromDegrees" and "toDegrees" from the < rotate > tag:
This is the code for custom_progress.xml (you can customize yours as you like but you must not modify "fromDegrees" and "toDegrees")
<?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
android:innerRadiusRatio="2.3"
android:shape="ring"
android:useLevel="false"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#0099ff"/>
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="-90"
android:toDegrees="-90">
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:angle="0"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#e0e0e0"/>
</shape>
</rotate>
</item>
</layer-list>
And for your progress bar you have to set this attributes:
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="100dp"
android:layout_height="100dp"
android:indeterminate="false"
android:max="100"
android:progress="20"
android:progressDrawable="#drawable/custom_progress" />
What is happening here is that the progress will start in degree -90 which for me is the top side of the progress bar view and towards the right and it will continue towards the same degree, this will make the view progress to start and end in the same degree.
NOTE:
If you set 0 for both "fromDegrees" and "toDegrees" the progress will start from the right side of the circle.
Hope it helps people with the same requirement.
Since Api 21 you can do something like that: Assuming that your ProgressBar defind this way:
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/progressBarStyleLarge"
android:id="#+id/progress_bar"
android:layout_width="#dimen/item_width"
android:layout_height="#dimen/item_height"
android:clickable="false"
android:indeterminate="true"
android:indeterminateDrawable="#drawable/progress"/>
and this is progress.xml:
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="76dip"
android:width="76dip" />
<gradient
android:angle="0"
android:endColor="#color/colorGrayText"
android:startColor="#android:color/transparent"
android:type="sweep"
android:useLevel="false" />
</shape>
Now you can do this on your ProgressBar:
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
if (progressBar != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
RotateDrawable rotateDrawable = (RotateDrawable) progressBar.getIndeterminateDrawable();
rotateDrawable.setToDegrees(0);
}
}
Like toadzky commented, there's no baked-in method. You might try this ProgressWheel. If nothing else, it should give you idea of how to implement it.
For determinate progress bar means the progress bar which doesn't keep on rotating and user can set a fixed percentage over that.
<ProgressBar
android:id="#+id/pb_sharpness"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="#dimen/dp_50"
android:layout_height="#dimen/dp_50"
android:layout_marginTop="#dimen/dp_16"
android:indeterminate="false"
android:max="100"
android:progressDrawable="#drawable/custom_progress_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
For adding drawable to above 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
android:innerRadiusRatio="2.3"
android:shape="ring"
android:useLevel="false"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#color/white_color"/>
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="180"
android:toDegrees="0"
>
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:angle="0"
android:type="sweep"
android:thicknessRatio="15.0">
<gradient
android:startColor="#color/color_5646F3"
android:endColor="#color/color_ED88FE" />
</shape>
</rotate>
</item>
You can access the visibility property of the progress bar and set it to invisible when you need it to be invisible like this
ProgressBar progressBar = view.findViewById<ProgressBar>(R.id.progressbar)
progressBar.visibility = ProgressBar.INVISIBLE
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
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">
The easiest way is to use
android:indeterminateTint attribute:
<ProgressBar
android:indeterminate="true"
android:indeterminateTint="#android:color/black"
........... />
This is an old question, but using theme is not mentioned here. If your default theme is using AppCompat, your ProgressBar's color will be colorAccent you have defined.
Changing colorAccent will also change your ProgressBar's color, but these changes also reflects at multiple places. So, if you want a different color just for a specific ProgressBar you can do that by applying theme to that ProgressBar alone:
Extend your default theme and override colorAccent
<style name="AppTheme.WhiteAccent">
<item name="colorAccent">#color/white</item> <!-- Whatever color you want-->
</style>
And in ProgressBar add the android:theme attribute:
android:theme="#style/AppTheme.WhiteAccent"
So it will look something like this:
<ProgressBar
android:id="#+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:theme="#style/AppTheme.WhiteAccent" />
So you are just changing a colorAccent for your particular ProgressBar.
Note: Using style will not work. You need to use android:theme only.
You can find more use of theme here: https://plus.google.com/u/0/+AndroidDevelopers/posts/JXHKyhsWHAH
Edit
Here is the code for changing the color of ProgressBar by programatically.
ProgressBar progressBar = (ProgressBar) findViewById(R.id.pb_listProgressBar);
int colorCodeDark = Color.parseColor("#F44336");
progressBar.setIndeterminateTintList(ColorStateList.valueOf(colorCodeDark));
Go to the declaration of the progress bar in your .xml file :
And paste this line of code :
android:indeterminateTint="#color/white"
The example above allows you to change the color of your progress bar to white. Now it's up to you to adapt it to the color you want.
Only for Android API >= 21
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"/>
for me, these two lines had to be there for it to work and change the color:
android:indeterminateTint="#color/yourColor"
android:indeterminateTintMode="src_in"
PS: but its only available from android 21
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" />
You can also change the color of your progressbar programmatically in your activities oncreate or your fragments onViewCreated()
pBar.getIndeterminateDrawable().setColorFilter(0xFFFF0000, android.graphics.PorterDuff.Mode.MULTIPLY);
Here the color applied is "0xFFFF0000" which is red. You can change it according to your needs
here is how you can do it by java code.
progressBar.getProgressDrawable().setColorFilter(ContextCompat.getColor(getActivity(),R.color.product_status_color), PorterDuff.Mode.MULTIPLY)
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.
I'm using android 2.3.1 version. I create a xml file called progressbar and call it in the layout progress bar tag android:progressDrawable="#drawable/progressbar"
<item android:id="#+id/progress">
<clip>
<shape>
<gradient android:startColor="#color/textColor"
android:centerColor="#color/textColor"
android:endColor="#color/textColor"
android:gradientRadius="20dp"
>
</gradient>
</shape>
</clip>
</item>
The Chirag's answer is right, but not all.
I think the XML file should look like this:
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="#drawable/progress"/>
you also can change only the attribute
android:indeterminateDrawable="#drawable/yourxmlfile"
and keep this style
style="#android:style/Widget.ProgressBar.Small"
Try using this in your XML
android:indeterminateDrawable="#drawable/yourxmlfile"
style="#android:style/Widget.ProgressBar.Small"