LinearProgressIndicator

public class LinearProgressIndicator extends BaseProgressIndicator


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

static final int
static final int

Used in the indeterminate animation type setter for contiguous animation, which animates the connecting active segment(s) occupying the full track.

static final int

Used in the indeterminate animation type setter for disjoint animation, which animates the active segment(s) with noticeable gaps.

static final int
static final int
static final int
static final int

Public constructors

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

Public methods

int

Returns the type of indeterminate animation of this progress indicator.

int

Returns the indicator animating direction used in this progress indicator.

int

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

Integer

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

int

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
setTrackInnerCornerRadius(int trackInnerCornerRadius)

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

void
setTrackInnerCornerRadiusFraction(
    float trackInnerCornerRadiusFraction
)

Sets the radius of the rounded inner corner for the indicator and track in fraction of the track thickness.

void
setTrackStopIndicatorPadding(Integer trackStopIndicatorPadding)

Sets the padding of the stop indicator at the end of the 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 Constants

From com.google.android.material.progressindicator.BaseProgressIndicator
static final int
static final int
static final int
static final int
static final int
static final int
static final int

Inherited methods

From com.google.android.material.progressindicator.BaseProgressIndicator
void
applyNewVisibility(boolean animate)

If it changes to visible, the start animation will be started if showAnimationBehavior indicates any.

Drawable

Returns the corresponding drawable based on current indeterminate state.

int

Returns the hide animation behavior used in this progress indicator.

IndeterminateDrawable<S>
int[]

Returns the array of colors used in the indicator of this progress indicator.

int

Returns the size of the gap between the indicator and track in pixels.

DeterminateDrawable<S>
int

Returns the show animation behavior used in this progress indicator.

int

Returns the color used in the track of this progress indicator.

int

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

float

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

int

Returns the track thickness of this progress indicator in pixels.

int

Returns the amplitude of the indicator's amplitude in pixels.

int

Returns the speed of the indicator's waveform in pixels.

int

Returns the wavelength, in pixels, of the indicator's waveform in determinate mode.

int

Returns the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

void

Hides the progress indicator.

void
void
void
synchronized void
onDraw(Canvas canvas)
synchronized void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onVisibilityChanged(View changedView, int visibility)
void
onWindowVisibilityChanged(int visibility)
void
setHideAnimationBehavior(int hideAnimationBehavior)

Sets the hide animation behavior used in this progress indicator.

synchronized void
setIndeterminate(boolean indeterminate)

Sets the progress mode of the progress indicator.

void
setIndeterminateAnimatorDurationScale(
    float indeterminateAnimatorDurationScale
)

Sets the scale of the animation duration in indeterminate mode.

void
setIndeterminateDrawable(Drawable drawable)

Sets a new indeterminate drawable.

void
setIndicatorTrackGapSize(int indicatorTrackGapSize)

Sets the size of the gap between the indicator and track in pixels.

synchronized void
setProgress(int progress)

Sets the current progress to the specified value.

void
setProgressDrawable(Drawable drawable)

Sets a new progress drawable.

void
setShowAnimationBehavior(int showAnimationBehavior)

Sets the show animation behavior used in this progress indicator.

void
setTrackColor(int trackColor)

Sets the color of the track of this progress indicator.

void

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

void
setTrackThickness(int trackThickness)

Sets the track thickness of this progress indicator.

void
setVisibilityAfterHide(int visibility)

Sets the visibility which the component will be after hide animation finishes.

void
setWaveAmplitude(int waveAmplitude)

Sets the amplitude of the indicator's amplitude in pixels.

void
setWaveSpeed(int waveSpeed)

Sets the speed of the indicator's waveform in pixels.

void
setWavelength(int wavelength)

Sets the wavelength of the indicator's determinate and indeterminate waveform in pixels.

void
setWavelengthDeterminate(int wavelength)

Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

void

Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

void

Shows the progress indicator.

Constants

DEF_STYLE_RES

public static final int DEF_STYLE_RES

INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS

public static final int INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS = 0

Used in the indeterminate animation type setter for contiguous animation, which animates the connecting active segment(s) occupying the full track.

INDETERMINATE_ANIMATION_TYPE_DISJOINT

public static final int INDETERMINATE_ANIMATION_TYPE_DISJOINT = 1

Used in the indeterminate animation type setter for disjoint animation, which animates the active segment(s) with noticeable gaps.

INDICATOR_DIRECTION_END_TO_START

public static final int INDICATOR_DIRECTION_END_TO_START = 3

INDICATOR_DIRECTION_LEFT_TO_RIGHT

public static final int INDICATOR_DIRECTION_LEFT_TO_RIGHT = 0

INDICATOR_DIRECTION_RIGHT_TO_LEFT

public static final int INDICATOR_DIRECTION_RIGHT_TO_LEFT = 1

INDICATOR_DIRECTION_START_TO_END

public static final int INDICATOR_DIRECTION_START_TO_END = 2

Public constructors

LinearProgressIndicator

public LinearProgressIndicator(Context context)

LinearProgressIndicator

public LinearProgressIndicator(Context context, AttributeSet attrs)

LinearProgressIndicator

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

Public methods

getIndeterminateAnimationType

public int getIndeterminateAnimationType()

Returns the type of indeterminate animation of this progress indicator.

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_indeterminateAnimationType

getIndicatorDirection

public int getIndicatorDirection()

Returns the indicator animating direction used in this progress indicator.

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_indicatorDirectionLinear

getTrackInnerCornerRadius

public int getTrackInnerCornerRadius()

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

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackInnerCornerRadius

getTrackStopIndicatorPadding

public Integer getTrackStopIndicatorPadding()

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

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackStopIndicatorPadding

getTrackStopIndicatorSize

public int getTrackStopIndicatorSize()

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

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackStopIndicatorSize

setIndeterminateAnimationType

public void setIndeterminateAnimationType(int indeterminateAnimationType)

Sets the type of indeterminate animation.

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_indeterminateAnimationType

Parameters
int indeterminateAnimationType

The new type of indeterminate animation.

setIndicatorColor

public void setIndicatorColor(int[] indicatorColors)

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

Parameters
int[] indicatorColors

The new colors used in indicator.

Throws
java.lang.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.

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_indicatorDirectionLinear

Parameters
int indicatorDirection

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
int progress

The new progress value.

boolean animated

Whether to update the progress with the animation.

See also
setProgress

setTrackCornerRadius

public void setTrackCornerRadius(int trackCornerRadius)

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

Parameters
int trackCornerRadius

The new corner radius in pixels.

Throws
java.lang.IllegalArgumentException

if trackCornerRadius is not zero, when indeterminateAnimationType is INDETERMINATE_ANIMATION_TYPE_CONTIGUOUS.

setTrackInnerCornerRadius

public void setTrackInnerCornerRadius(int trackInnerCornerRadius)

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

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackInnerCornerRadius

Parameters
int trackInnerCornerRadius

The new corner radius in pixels.

setTrackInnerCornerRadiusFraction

public void setTrackInnerCornerRadiusFraction(
    float trackInnerCornerRadiusFraction
)

Sets the radius of the rounded inner corner for the indicator and track in fraction of the track thickness.

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackInnerCornerRadius

Parameters
float trackInnerCornerRadiusFraction

The new corner radius in fraction of the track thickness.

setTrackStopIndicatorPadding

public void setTrackStopIndicatorPadding(Integer trackStopIndicatorPadding)

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

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackStopIndicatorPadding

Parameters
Integer trackStopIndicatorPadding

The new stop indicator padding in pixels.

setTrackStopIndicatorSize

public void setTrackStopIndicatorSize(int trackStopIndicatorSize)

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

ref com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackStopIndicatorSize

Parameters
int trackStopIndicatorSize

The new stop indicator size in pixels.

Protected methods

onLayout

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

onSizeChanged

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