nikoyuwono / static-progress-bar Goto Github PK
View Code? Open in Web Editor NEWCustom static progress bar for Android where you can set your own shape and color.
License: MIT License
Custom static progress bar for Android where you can set your own shape and color.
License: MIT License
I love this class. I think it's so awesome and is my favorite progress bar so far. Few things:
getColor()
is deprecated. Replace getResources().getColor(
with ContextCompat.getColor(getContext(),
in lines 75&76.I thought about introducing a drawable layer-list like this but wasn't sure if I could do it since we're extending from a textView:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/Color">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="0"
android:centerColor="@color/amber_500"
android:centerY="0.5"
android:endColor="@color/red_500"
android:startColor="@color/green_500" />
</shape>
</item>
</layer-list>
Or using:
getPaint().setShader(new LinearGradient(0,0,0,textView.getLineHeight(), startColor, endColor, Shader.TileMode.REPEAT));
Loving this Progress Bar.
When you change the orientation from landscape to portrait the screen doesn't refresh correctly. You should call resetWidth() in the initView() method.
I'm sorry but i don't see how do I set the current progress or percentage for the progress bar, there is a setMaximun percentage and getCurrentPercentage but there is no setCurrentPercentage or setProgress method?.
Hey there,
This is a great library, but it would be useful if there was a Gradle repository so this lib can be integrated into an app with ease.
Thanks!
I'm setting that value after the CustomProgress is created so it does nothing and gets the default value??
This is how I finally implemented the static progress bar:
my_activity.xml
ProgressBar
android:id="@+id/npsProgressBar"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:gravity="center"
style="@style/CustomProgressBar"
android:layout_width="match_parent"
android:layout_height="@dimen/custom_progress_height"/>
styles.xml
<style name="CustomProgressBar" parent="android:Widget.ProgressBar.Horizontal">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@drawable/custom_progress_bar</item>
<item name="android:minHeight">10dip</item>
<item name="android:maxHeight">20dip</item>
</style>
inside drawable folder: custom_progress_bar.xml
?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>
padding
android:bottom="3dip"
android:top="3dip"
android:left="3dip"
android:right="3dip"
/>
corners
android:radius="5dip" />
gradient
android:startColor="@color/main_blue_light"
android:centerColor="@color/main_blue_light"
android:centerY="0.50"
android:endColor="@color/main_blue_light"
android:angle="270" />
corners
android:radius="5dip" />
gradient
android:startColor="@color/main_blue"
android:endColor="@color/main_blue"
android:angle="90" />
MyActivity.java
private int mProgressNpsStatus = 0;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
...
npsProgressBar = (ProgressBar) findViewById(R.id.npsProgressBar);
animateNpsProgressBar();
}
//method to animate the progress
private void animateNpsProgressBar(){
// Start lengthy operation in a background thread
new Thread(new Runnable() {
public void run() {
while (mProgressNpsStatus < (int) 50) {
mProgressNpsStatus += 1;
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
npsProgressBar.setProgress(mProgressNpsStatus);
npsNumberTextView.setText(mProgressNpsStatus + "%");
}
});
try {
//Display progress slowly
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.