A simple nice android ProgressBar view which can be easily customized, and also it's value can be easily modified.
Changable attributes are size (Width, Height), foreground (Progress) colour, background colour, border colour, and filling direction including up to down and down to up (Verical Filling) and (Horizontal Filling).
- First add it to your project by adding this implementation to your Project's
app gradle.build
dependencies:-
dependencies {
implementation 'com.example.easyprogressbar:easyprogressbar:0.1.0'
}
-
And add to your activity using one of the below described ways:-
- Add the view into your layout XML file:-
<com.example.easyprogressbar.EasyProgressBar android:id="@+id/progressBar" android:layout_width="50dp" android:layout_height="match_parent" android:layout_marginLeft="50dp" android:layout_marginStart="50dp" android:layout_marginTop="250dp" android:layout_centerVertical="true" app:backColor="#2FFFC400" app:foreColor="#FABC00" app:value="10.0" app:maxValue="50.0" app:fillDirection="downToUp"/>
- Or Add it programmatically in the java code:-
EasyProgressBar progressBar = new EasyProgressBar(this, Color.WHITE, Color.GREEN, EasyProgressBar.LEFT_TO_RIGHT); progressBar.setBorderColor(Color.WHITE); RelativeLayout parent = findViewById(R.id.parent); parent.addView(progressBar); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) progressBar.getLayoutParams(); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); layoutParams.height = 10; layoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT; progressBar.setLayoutParams(layoutParams);
backColor
: The color of the backgound(unfilled) area of the progress bar.foreColor
: The color of the filled area of the progress bar.border
: The color of the frame of the progress bar.foreColor
: The color of the filled area of the progress bar.fillDirection
: The direction of filling progress, options are (leftToRight
,rightToLeft
,upToDown
,downToUp
).value
: Current progress value of the progress bar which measured permaxValue
.maxValue
: Max value of the progress bar.
there are setters and getters for every attribute, and also some other methods such as:-
- Constructor
public EasyProgressBar(Context context, int backColor, int foreColor, int fillDirection)
let you create the view programmatically with these parameters which described before. void setValue(double progressValue)
: sets the current progress value toprogressValue
.void setMaxValue(double maxValue)
: sets the max value tomaxValue
and the value would be changed to fit the before position per the newmaxValue
.void addValue(double valueToAdd)
: addsvalueToAdd
to the current progress value.void addValueAnimated(double valueToAdd_, final double seconds, final int frames)
: addsvalueToAdd_
to the progress bar or fill it like an animation permaxValue
, theseconds
parameter is the number of the seconds the animation spend to complete, and theframes
parameter is the refresh rate of the animation perseconds
parameter.void addValueAnimated(double valueToAdd_, final double seconds, final int frames, final Runnable afterAdded)
: this method is exactly like the bove method instead of this is listenening to completion time and then run theafterAdded
tasks after the animation completed.
- You can't animate a view when its currently animating.
- You can't use numbers below zero to the
value
, and also for themaxValue
. maxValue
should be bigger than zero.maxValue
's default value is100
.- you can set the
width
and theheight
of the view as you like.