Horizontal progress bar with icon - android

In my project I want to make a horizontal progress bar similar to the following.
I've tried a lot of libraries but none of them have this feature. Is there any way to make this?
Here is my code:
dialog = new ProgressDialog(Context.this);
dialog.setIndeterminate(true);
dialog.setMessage("Some Text");
dialog.show();

You should use seekBar instead of progressDialog. And you can add android:thumb icon.
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumb="#drawable/icon"
android:max="10"
android:progress="5"
android:progressDrawable="#drawable/custom_seekbar" />
custom-seekbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/progress">
<clip>
<shape android:shape="rectangle">
<size
android:width="12dp"
android:height="12dp" />
<corners android:radius="15dp" />
<solid android:color="#4fc3f7" />
<gradient
android:angle="270"
android:centerColor="#4fc3f7"
android:endColor="#4fc3f7"
android:startColor="#4fc3f7" />
</shape>
</clip>
</item>
</layer-list>

Related

How to add gradient color and rounded indicator to LinearProgressBar in Android?

This is the Progress indicator I need.
I took help from this answer. Gradient color Progress Indicator
This is what I achieved so far.
My Progressbar background drawable is:
<?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="#dimen/_11sdp" />
<solid android:color="#color/cultured" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip android:clipOrientation="horizontal">
<shape android:shape="rectangle">
<corners android:radius="#dimen/_11sdp" />
<gradient
android:endColor="#color/colorPrimary"
android:startColor="#color/deep_peach" />
</shape>
</clip>
</item>
</layer-list>
My Progressbar code is:
<ProgressBar
android:id="#+id/viewLinearProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="4dp"
android:layout_marginStart="#dimen/_6sdp"
android:layout_marginTop="#dimen/_19sdp"
android:layout_marginEnd="#dimen/_14sdp"
android:progress="60"
android:progressDrawable="#drawable/gradient_progressbar"
app:layout_constraintEnd_toStartOf="#id/tvProgress"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tvMessage" />
The only problem is that - only the Progressbar indicator right side rounded corner is not resolved. The track is ok.
This is working
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background" android:top="#dimen/size_6" android:bottom="#dimen/size_6">
<shape>
<solid android:color="#B5B6B5"/>
<corners android:radius="100dp" />
</shape>
</item>
<item android:id="#android:id/progress"
android:top="#dimen/size_4" android:bottom="#dimen/size_4">
<clip>
<scale android:scaleWidth="100%" android:scaleHeight="20">
<shape>
<gradient android:endColor="#FF7400" android:startColor="#FFA119" android:angle="180"/>
<corners android:radius="100dp" />
</shape>
</scale>
</clip>
</item>
</layer-list>
Use
<ProgressBar
android:id="#+id/progressbar_insurance"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="#dimen/_14sdp"
android:layout_marginTop="#dimen/_4sdp"
android:indeterminate="false" />
Hope this work for you, let me know if doesn't work... :)

How to create horizontal indeterminate progress drawable with round corners for progressbar in android?

I want to create horizontal indeterminate progress drawable with round corners for progress bar in android. How to create that using xml?
Edit 1: I am using following drawable:
<?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>
<solid android:color="?attr/dividerAndProgressColor" />
<corners android:radius="20dp" />
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="?attr/secondaryText" />
<corners android:radius="20dp" />
</shape>
</clip>
</item>
<item
android:id="#android:id/progress"
>
<clip>
<shape>
<solid android:color="?attr/secondaryText" />
<corners android:radius="20dp" />
</shape>
</clip>
</item>
</layer-list>
android:indeterminateDrawable="#drawable/progress_drawable_start_end_indeterminate"
But there is one problem, animation starts from 0 reaches 100 and then restarts. This is not desired in case of indeterminate progressbar.
round corner
lookout this, https://stackoverflow.com/a/42646939/12709358
<ProgressBar
android:id="#+id/progressbar_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminateOnly="true"
android:indeterminateDrawable="#drawable/progressbar_indeterminate_horizontal"
android:progressDrawable="#drawable/progressbar_horizontal"
android:minHeight="24dip"
android:maxHeight="24dip"
/>
also see this, https://stackoverflow.com/a/63463786/12709358

Secondary progress not visible

Secondary progress in SeekBar is not visible.
If I am not giving progress in drawable it is overriding secondary
progress as primary progress
seekbar_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/secondaryProgress">
<clip>
<shape android:shape="line">
<stroke
android:width="3dp"
android:color="#color/color_status_bar" />
</shape>
</clip>
</item>
</layer-list>
Custom SeekBar is showing on progress but not secondary progress.
When deleting
<item android:id="#android:id/progress">
<clip>
<shape android:shape="line">
<stroke
android:width="3dp"
android:color="#color/color_status_bar" />
</shape>
</clip>
</item>
from XML it is taking secondary progress as primary progress.
Use Secondary Progress attribute in xml, this worked for me.
<SeekBar
android:id="#+id/seekbar_voice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:progressDrawable="#drawable/seekbar_progress"
android:secondaryProgress="100"
android:splitTrack="false"
android:thumb="#drawable/custom_thumb" />

How to set progress bar color?

I am trying to set different color to the rounded progress bar. Below is my code..
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#color/purple" />
</shape>
</clip>
<color android:color="#color/purple" />
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#color/purple" />
</shape>
</clip>
<color android:color="#color/purple" />
</item>
</layer-list>
<ProgressBar
android:id="#+id/progress_bar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:progressDrawable="#drawable/progress_bar"
android:visibility="visible" />
But this is not working. Still the progress bar is showing with gray color.
Please help me, where i am going wrong?
Make one xml folder in res directory and put the progress.xml file in it .
progress.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="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>
set startColor and endColor as per your choice .
now set that progress.xml in progressbar's backgound .
Like this
<ProgressBar
android:id="#+id/ProgressBar01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background ="#xml/progress">
Create an XML file named customprogressbar.xml in your res->drawable folder:
customprogressbarcolour.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="#android:id/background">
<shape>
<gradient
android:startColor="#000001"
android:centerColor="#0b131e"
android:centerY="1.0"
android:endColor="#0d1522"
android:angle="270"
/>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="#android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#007A00"
android:centerColor="#007A00"
android:centerY="1.0"
android:endColor="#06101d"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
Do the following in your XML:
<ProgressBar
android:id="#+id/progress1"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="#drawable/custom_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
At run time
Drawable draw=res.getDrawable(R.drawable.customprogressbarcolour);
progressBar.setProgressDrawable(draw);

custom progress drawable not showing sometimes

I have a very strange problem - I defined a custom progress drawable for a progress bar and
sometimes it shows and sometimes its not.
I tried cleaning my project, restarting eclipse and even restart the computer.
its still happens.
here is the progress drawable 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
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<gradient
android:startColor="#6f7754"
android:endColor="#858762"
android:angle="90"/>
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<gradient
android:startColor="#ffba00"
android:endColor="#af6c03"
android:angle="90"/>
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp" />
<gradient
android:startColor="#ffba00"
android:endColor="#af6c03"
android:angle="90" />
</shape>
</clip>
and here's the xml where I use it:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="2dp"
android:background="#drawable/quick_action_item_btn">
<ImageView
android:id="#+id/icon"
android:layout_width="21dp"
android:layout_height="21dp"
android:scaleType="centerInside"/>
<ProgressBar
android:id="#+id/progress"
android:layout_width="20dp"
android:layout_height="4dp"
android:layout_marginTop="2dp"
style="#android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="#drawable/achievement_progress_bar"/>
</LinearLayout>
try with this
android:indeterminateDrawable="#drawable/yourXML"
it is working for me..
Its working fine for me. Just set your indeterminateDrawable to your custum xml file.It should be fine..
Perhaps this a similar problem to this one... SharedPreferences.onSharedPreferenceChangeListener not being called consistently
Is the custom xml defined as a variable of the activity? If not, perhaps it is being collected by the garbage collector. My suggestion is to make it a field variable of the class (the activity class).

Categories

Resources