LinearProgressIndicator

public class LinearProgressIndicator
extends BaseProgressIndicator<LinearProgressIndicatorSpec>

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ProgressBar
       ↳ com.google.android.material.progressindicator.BaseProgressIndicator<com.google.android.material.progressindicator.LinearProgressIndicatorSpec>
         ↳ com.google.android.material.progressindicator.LinearProgressIndicator


This class implements the linear type progress indicators.

With the default style Widget.MaterialComponents.LinearProgressIndicator, 4dp indicator/track thickness is used without animation is used for visibility change. Without customization, primaryColor will be used as the indicator color; the track is the (first) indicator color applying the disabledAlpha. The following attributes can be used to customize the component's appearance:

  • trackThickness: the thickness of the indicator and track.
  • indicatorColor: the color(s) of the indicator.
  • trackColor: the color of the track.
  • trackCornerRadius: the radius of the rounded corner of the indicator and track.
  • indeterminateAnimationType: the type of indeterminate animation.
  • indicatorDirectionLinear: the sweeping direction of the indicator.

For more information, see the component developer guidance and design guidelines.

Summary

Constants

int INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS

int INDETERMINATE_ANIMATION_TYPE_DISJOINT

int INDICATOR_DIRECTION_END_TO_START

int INDICATOR_DIRECTION_LEFT_TO_RIGHT

int INDICATOR_DIRECTION_RIGHT_TO_LEFT

int INDICATOR_DIRECTION_START_TO_END

Inherited constants

Fields

public static final int DEF_STYLE_RES

Inherited fields

Public constructors

LinearProgressIndicator(Context context)
LinearProgressIndicator(Context context, AttributeSet attrs)
LinearProgressIndicator(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

int getIndeterminateAnimationType()

Returns the type of indeterminate animation of this progress indicator.

int getIndicatorDirection()

Returns the indicator animating direction used in this progress indicator.

int getTrackStopIndicatorSize()

Returns the size of the stop indicator at the end of the track in pixels.

void setIndeterminateAnimationType(int indeterminateAnimationType)

Sets the type of indeterminate animation.

void setIndicatorColor(int... indicatorColors)

Sets the colors used in the indicator of this progress indicator.

void setIndicatorDirection(int indicatorDirection)

Sets the indicator animating direction used in this progress indicator.

void setProgressCompat(int progress, boolean animated)

Sets the current progress to the specified value with/without animation based on the input.

void setTrackCornerRadius(int trackCornerRadius)

Sets the radius of the rounded corner for the indicator and track in pixels.

void setTrackStopIndicatorSize(int trackStopIndicatorSize)

Sets the size of the stop indicator at the end of the track in pixels.

Protected methods

void onLayout(boolean changed, int left, int top, int right, int bottom)
void onSizeChanged(int w, int h, int oldw, int oldh)

Inherited methods

Constants

INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS

public static final int INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS

Constant Value: 0 (0x00000000)

INDETERMINATE_ANIMATION_TYPE_DISJOINT

public static final int INDETERMINATE_ANIMATION_TYPE_DISJOINT

Constant Value: 1 (0x00000001)

INDICATOR_DIRECTION_END_TO_START

public static final int INDICATOR_DIRECTION_END_TO_START

Constant Value: 3 (0x00000003)

INDICATOR_DIRECTION_LEFT_TO_RIGHT

public static final int INDICATOR_DIRECTION_LEFT_TO_RIGHT

Constant Value: 0 (0x00000000)

INDICATOR_DIRECTION_RIGHT_TO_LEFT

public static final int INDICATOR_DIRECTION_RIGHT_TO_LEFT

Constant Value: 1 (0x00000001)

INDICATOR_DIRECTION_START_TO_END

public static final int INDICATOR_DIRECTION_START_TO_END

Constant Value: 2 (0x00000002)

Fields

DEF_STYLE_RES

public static final int DEF_STYLE_RES

Public constructors

LinearProgressIndicator

public LinearProgressIndicator (Context context)

Parameters
context Context

LinearProgressIndicator

public LinearProgressIndicator (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

LinearProgressIndicator

public LinearProgressIndicator (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

getIndeterminateAnimationType

public int getIndeterminateAnimationType ()

Returns the type of indeterminate animation of this progress indicator.

Returns
int

getIndicatorDirection

public int getIndicatorDirection ()

Returns the indicator animating direction used in this progress indicator.

Returns
int

getTrackStopIndicatorSize

public int getTrackStopIndicatorSize ()

Returns the size of the stop indicator at the end of the track in pixels.

Returns
int

setIndeterminateAnimationType

public void setIndeterminateAnimationType (int indeterminateAnimationType)

Sets the type of indeterminate animation.

Parameters
indeterminateAnimationType int: The new type of indeterminate animation.

setIndicatorColor

public void setIndicatorColor (int... indicatorColors)

Sets the colors used in the indicator of this progress indicator.

Parameters
indicatorColors int: The new colors used in indicator.

Throws
IllegalArgumentException if there are less than 3 indicator colors when indeterminateAnimationType is INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS.

setIndicatorDirection

public void setIndicatorDirection (int indicatorDirection)

Sets the indicator animating direction used in this progress indicator.

Parameters
indicatorDirection int: The new indicator direction.

setProgressCompat

public void setProgressCompat (int progress, 
                boolean animated)

Sets the current progress to the specified value with/without animation based on the input.

If it's in the indeterminate mode and using disjoint animation, it will smoothly transition to determinate mode by finishing the current indeterminate animation cycle.

Parameters
progress int: The new progress value.

animated boolean: Whether to update the progress with the animation.

setTrackCornerRadius

public void setTrackCornerRadius (int trackCornerRadius)

Sets the radius of the rounded corner for the indicator and track in pixels.

Parameters
trackCornerRadius int: The new corner radius in pixels.

Throws
IllegalArgumentException if trackCornerRadius is not zero, when indeterminateAnimationType is INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS.

setTrackStopIndicatorSize

public void setTrackStopIndicatorSize (int trackStopIndicatorSize)

Sets the size of the stop indicator at the end of the track in pixels.

Parameters
trackStopIndicatorSize int: The new stop indicator size in pixels.

Protected methods

onLayout

protected void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

Parameters
changed boolean

left int

top int

right int

bottom int

onSizeChanged

protected void onSizeChanged (int w, 
                int h, 
                int oldw, 
                int oldh)

Parameters
w int

h int

oldw int

oldh int