Color ProgressBar

I want to set the Progressbar color indicator in my application, since the indicator color is set to “Slightly White” by default, and “My Application” also has a white background, so it may not be visible correctly. So please give me a solution for this. Thanks.

+6
source share
4 answers

@Chirag: I do not think this will be enough? Your code will probably set the gradient in the background, but the white counter will still be here.

What I did to set up my work counter was to set the ProgressBar with the background highlighted (image or shape). The ProgressBar animation here is called Java.

<ProgressBar android:id="@+id/ProgressBar01" android:layout_width="40px" android:layout_height="40px" style="?android:attr/progressBarStyle" android:indeterminateOnly="false" android:background ="@drawable/spinner_blue_76" /> 

splash_spinner.xml

 <?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="359" android:duration="1000" android:repeatMode="restart" android:repeatCount="infinite" android:interpolator="@android:anim/linear_interpolator"> </rotate> 

LauncherActivity

  ... ProgressBar t = (ProgressBar) findViewById(R.id.ProgressBar01); t.startAnimation(AnimationUtils.loadAnimation(this,R.anim.splash_spinner)); ... 

spinner_blue_76 (or something else)

enter image description here

This may not be the right approach, but it works well. (I now have a blue spinner on my gray background)

+10
source

Make one name for the xml progress.xml file and put it in the res / xml folder and write the code below in this 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 this xml for progressbars background ..

how

 <ProgressBar android:id="@+id/ProgressBar01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background = "@xml/progress"> 
+5
source

Not the correct answer, but still I did this: To get the black ProgressBar, use one of the reverse styles:

 <ProgressBar style="@android:style/Widget.ProgressBar.Inverse"/> <ProgressBar style="@android:style/Widget.ProgressBar.Large.Inverse"/> <ProgressBar style="@android:style/Widget.ProgressBar.Small.Inverse"/> 

For this you need to have a minimum Android SDK level 4 (Android 1.6).

+3
source

For the horizontal style of the ProgressBar, I use:

  import android.widget.ProgressBar; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.ClipDrawable; import android.view.Gravity; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; public void setColours(ProgressBar progressBar, int bgCol1, int bgCol2, int fg1Col1, int fg1Col2, int value1, int fg2Col1, int fg2Col2, int value2) { //If solid colours are required for an element, then set //that elements Col1 param s the same as its Col2 param //(eg fg1Col1 == fg1Col2). //fgGradDirection and/or bgGradDirection could be parameters //if you require other gradient directions eg LEFT_RIGHT. GradientDrawable.Orientation fgGradDirection = GradientDrawable.Orientation.TOP_BOTTOM; GradientDrawable.Orientation bgGradDirection = GradientDrawable.Orientation.TOP_BOTTOM; //Background GradientDrawable bgGradDrawable = new GradientDrawable( bgGradDirection, new int[]{bgCol1, bgCol2}); bgGradDrawable.setShape(GradientDrawable.RECTANGLE); bgGradDrawable.setCornerRadius(5); ClipDrawable bgclip = new ClipDrawable( bgGradDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); bgclip.setLevel(10000); //SecondaryProgress GradientDrawable fg2GradDrawable = new GradientDrawable( fgGradDirection, new int[]{fg2Col1, fg2Col2}); fg2GradDrawable.setShape(GradientDrawable.RECTANGLE); fg2GradDrawable.setCornerRadius(5); ClipDrawable fg2clip = new ClipDrawable( fg2GradDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); //Progress GradientDrawable fg1GradDrawable = new GradientDrawable( fgGradDirection, new int[]{fg1Col1, fg1Col2}); fg1GradDrawable.setShape(GradientDrawable.RECTANGLE); fg1GradDrawable.setCornerRadius(5); ClipDrawable fg1clip = new ClipDrawable( fg1GradDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); //Setup LayerDrawable and assign to progressBar Drawable[] progressDrawables = {bgclip, fg2clip, fg1clip}; LayerDrawable progressLayerDrawable = new LayerDrawable(progressDrawables); progressLayerDrawable.setId(0, android.R.id.background); progressLayerDrawable.setId(1, android.R.id.secondaryProgress); progressLayerDrawable.setId(2, android.R.id.progress); //Copy the existing ProgressDrawable bounds to the new one. Rect bounds = progressBar.getProgressDrawable().getBounds(); progressBar.setProgressDrawable(progressLayerDrawable); progressBar.getProgressDrawable().setBounds(bounds); // setProgress() ignores a change to the same value, so: if (value1 == 0) progressBar.setProgress(1); else progressBar.setProgress(0); progressBar.setProgress(value1); // setSecondaryProgress() ignores a change to the same value, so: if (value2 == 0) progressBar.setSecondaryProgress(1); else progressBar.setSecondaryProgress(0); progressBar.setSecondaryProgress(value2); //now force a redraw progressBar.invalidate(); } 

Call example:

  setColours(myProgressBar, 0xff303030, //bgCol1 grey 0xff909090, //bgCol2 lighter grey 0xff0000FF, //fg1Col1 blue 0xffFFFFFF, //fg1Col2 white 50, //value1 0xffFF0000, //fg2Col1 red 0xffFFFFFF, //fg2Col2 white 75); //value2 

If you do not need "secondary progress", simply set value2 to value1.

+1
source

Source: https://habr.com/ru/post/885802/


All Articles