Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get dashed Horizontal Progressbar in Android?

I need to design a dashed progressbar as shown in attached.

enter image description here

This is what I have done so far, It displays a normal progressbar with two different colors, one for progress and another for other.

<ProgressBar
    android:id="@+id/progress_bar"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_width="match_parent"
    android:layout_height="3dp"
    android:progressDrawable="@drawable/bg_progress_bar_green"
    />

And bg_progress_bar_green is here

 <?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="#E0E1EA" />
    </shape>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <solid android:color="#66BA6B" />
        </shape>
    </clip>
</item>

And this is how I update the progressbar :

 progressBar.setProgress(numOfHours);

How do I get dashed line of bar as shown?

like image 688
Santhosh Avatar asked Jun 11 '26 06:06

Santhosh


1 Answers

You can use this library for your work Step Progress Bar. I'm providing code in case of link changed.

Gradle

dependencies {
   ...
   compile 'com.marcok.stepprogressbar:stepprogressbar:1.0.1'
}

Usage

 <com.marcok.stepprogressbar.StepProgressBar
    android:layout_centerVertical="true"
    android:layout_height="0dp"
    android:layout_width="wrap_content"
    android:id="@+id/stepProgressBar"
    app:cumulativeDots="false"
    app:activeDotIndex="0"
    app:activeDotColor="@color/material_deep_teal_500"
    app:inactiveDotColor="@color/material_blue_grey_800"
    app:activeDotIcon="@drawable/active_dot.png"
    app:inactiveDotIcon="@drawable/inactive_dot.png"
    app:numberDots="6"
    app:dotSize="20dp"
    app:spacing="20dp"/>
  • If dot icons are provided, they override dot colors
  • Layout height is irrelevant and determined by the dotSize

Java Code

  • To move to the next dot or previous dot:

    StepProgressBar mStepProgressBar =(StepProgressBar)findViewById(R.id.stepProgressBar); mStepProgressBar.next(); mStepProgressBar.previous();

    • To set the dots to be cumulative (all dots <= the specified index will show as active), call setCumulativeDots(true)

    • Calling setCurrentProgressDot(-1) will prevent any dots from showing as active. Any lower values will throw IndexOutOfBoundsExeption.

    • Other methods:

    setCurrentProgressDot(); setNumDots(); setActiveColor(); setInactiveColor(); setActiveDrawable(); setInactiveDrawable();

DRAWABLES FOR RECTANGLE PROGRESS

use these two drawbles..

inactive_dot.png inactive_dot.png

active_dot.png active_dot.png

like image 196
Abhishek Singh Avatar answered Jun 13 '26 21:06

Abhishek Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!