CollapsingToolbarLayout

public class CollapsingToolbarLayout


CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout. CollapsingToolbarLayout contains the following features:

Collapsing title A title which is larger when the layout is fully visible but collapses and becomes smaller as the layout is scrolled off screen. You can set the title to display via setTitle. The title appearance can be tweaked via the collapsedTextAppearance and expandedTextAppearance attributes. Content scrim A full-bleed scrim which is show or hidden when the scroll position has hit a certain threshold. You can change this via setContentScrim. Status bar scrim A scrim which is shown or hidden behind the status bar when the scroll position has hit a certain threshold. You can change this via setStatusBarScrim. This only works on LOLLIPOP devices when we set to fit system windows. Parallax scrolling children Child views can opt to be scrolled within this layout in a parallax fashion. See COLLAPSE_MODE_PARALLAX and setParallaxMultiplier. Pinned position children Child views can opt to be pinned in space globally. This is useful when implementing a collapsing as it allows the Toolbar to be fixed in place even though this layout is moving. See COLLAPSE_MODE_PIN.

Do not manually add views to the Toolbar at run time. We will add a 'dummy view' to the Toolbar which allows us to work out the available space for the title. This can interfere with any views which you add.

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

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_collapsedTitleTextAppearance

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleTextAppearance

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_contentScrim

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMargin

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginStart

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginEnd

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginBottom

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_statusBarScrim

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_toolbarId

Summary

Nested types

Constants

static final int

The expanded title will fade out and translate, and the collapsed title will fade in.

static final int

The expanded title will continuously scale and translate to its final collapsed position.

Public constructors

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

Public methods

void
draw(Canvas canvas)
LayoutParams
generateLayoutParams(AttributeSet attrs)
float

Returns the text size of the collapsed subtitle.

Typeface

Returns the typeface used for the collapsed subtitle.

int

Returns the horizontal and vertical alignment for titles when collapsed.

float

Returns the text size of the collapsed title.

Typeface

Returns the typeface used for the collapsed title.

Drawable

Returns the drawable which is used for the foreground scrim.

float

Returns the text size of the expanded subtitle.

Typeface

Returns the typeface used for the expanded subtitle.

int

Returns the horizontal and vertical alignment for titles when expanded.

int

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginBottom

int

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginEnd

int

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginStart

int

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginTop

int

Returns the spacing between the expanded title and subtitle in pixels

float

Returns the text size of the expanded title.

Typeface

Returns the typeface used for the expanded title.

int

Gets the hyphenation frequency of the title text, or -1 if not set.

int

Gets the current number of lines of the title text.

float

Gets the line spacing addition of the title text, or -1 if not set.

float

Gets the line spacing multiplier of the title text, or -1 if not set.

int

Gets the maximum number of lines to display in the expanded state.

long

Returns the duration in milliseconds used for scrim visibility animations.

int

Returns the amount of visible height in pixels used to define when to trigger a scrim visibility change.

Drawable

Returns the drawable which is used for the status bar scrim.

CharSequence

Returns the subtitle currently being displayed by this view.

CharSequence

Returns the title currently being displayed by this view.

int

Returns the current title collapse mode.

TimeInterpolator

Returns the interpolator being used to animate the title position from collapsed to expanded and vice versa.

TruncateAt

Get ellipsizing currently applied on the title text.

boolean

Gets whether extra height should be added when the title text spans across multiple lines.

boolean

Gets whether the top system window inset should be respected regardless of what the layout_height of the CollapsingToolbarLayout is set to.

boolean

Gets whether TextDirectionHeuristics should be used to determine whether the title text is RTL.

boolean

Returns whether this view is currently displaying its own title.

void

Sets the text color and size for the collapsed subtitle from the specified TextAppearance resource.

void

Sets the text color of the collapsed subtitle.

void
setCollapsedSubtitleTextColor(ColorStateList colors)

Sets the text colors of the collapsed subtitle.

void

Sets the text size of the collapsed subtitle.

void
setCollapsedSubtitleTypeface(Typeface typeface)

Set the typeface to use for the collapsed subtitle.

void

Sets the horizontal alignment of the collapsed titles and the vertical gravity that will be used when there is extra space in the collapsed bounds beyond what is required for the title itself.

void

Sets the text color and size for the collapsed title from the specified TextAppearance resource.

void

Sets the text color of the collapsed title.

void
setCollapsedTitleTextColor(ColorStateList colors)

Sets the text colors of the collapsed title.

void
setCollapsedTitleTextSize(float textSize)

Sets the text size of the collapsed title.

void
setCollapsedTitleTypeface(Typeface typeface)

Set the typeface to use for the collapsed title.

void
setContentScrim(Drawable drawable)

Set the drawable to use for the content scrim from resources.

void

Set the color to use for the content scrim.

void

Set the drawable to use for the content scrim from resources.

void

Sets the text color of the expanded subtitle.

void

Sets the text color and size for the expanded subtitle from the specified TextAppearance resource.

void
setExpandedSubtitleTextColor(ColorStateList colors)

Sets the text colors of the expanded subtitle.

void

Sets the text size of the expanded subtitle.

void
setExpandedSubtitleTypeface(Typeface typeface)

Set the typeface to use for the expanded subtitle.

void

Sets the text color of the expanded title.

void

Sets the horizontal alignment of the expanded titles and the vertical gravity that will be used when there is extra space in the expanded bounds beyond what is required for the title itself.

void
setExpandedTitleMargin(int start, int top, int end, int bottom)

Sets the expanded title margins.

void

Sets the bottom expanded title margin in pixels.

void

Sets the ending expanded title margin in pixels.

void

Sets the starting expanded title margin in pixels.

void

Sets the top expanded title margin in pixels.

void
setExpandedTitleSpacing(int titleSpacing)

Sets the spacing between the expanded title and subtitle.

void

Sets the text color and size for the expanded title from the specified TextAppearance resource.

void
setExpandedTitleTextColor(ColorStateList colors)

Sets the text colors of the expanded title.

void
setExpandedTitleTextSize(float textSize)

Sets the text size of the expanded title.

void
setExpandedTitleTypeface(Typeface typeface)

Set the typeface to use for the expanded title.

void
setExtraMultilineHeightEnabled(boolean extraMultilineHeightEnabled)

Sets whether extra height should be added when the title text spans across multiple lines.

void
setForceApplySystemWindowInsetTop(
    boolean forceApplySystemWindowInsetTop
)

Sets whether the top system window inset should be respected regardless of what the layout_height of the CollapsingToolbarLayout is set to.

void
setHyphenationFrequency(int hyphenationFrequency)

Sets the hyphenation frequency of the title text.

void
setLineSpacingAdd(float spacingAdd)

Sets the line spacing addition of the title text.

void
setLineSpacingMultiplier(float spacingMultiplier)

Sets the line spacing multiplier of the title text.

void
setMaxLines(int maxLines)

Sets the maximum number of lines to display in the expanded state.

void
setRtlTextDirectionHeuristicsEnabled(
    boolean rtlTextDirectionHeuristicsEnabled
)

Sets whether TextDirectionHeuristics should be used to determine whether the title text is RTL.

void

Set the duration used for scrim visibility animations.

void

Set the amount of visible height in pixels used to define when to trigger a scrim visibility change.

void
setScrimsShown(boolean shown)

Set whether the content scrim and/or status bar scrim should be shown or not.

void
setScrimsShown(boolean shown, boolean animate)

Set whether the content scrim and/or status bar scrim should be shown or not.

void
setStatusBarScrim(Drawable drawable)

Set the drawable to use for the status bar scrim from resources.

void

Set the color to use for the status bar scrim.

void

Set the drawable to use for the status bar scrim from resources.

void

Sets the subtitle to be displayed by this view, if enabled.

void

Sets the title to be displayed by this view, if enabled.

void
setTitleCollapseMode(int titleCollapseMode)

Sets the title collapse mode which determines the effect used to collapse and expand the title text.

void
setTitleEllipsize(TruncateAt ellipsize)

Set ellipsizing on the title text.

void
setTitleEnabled(boolean enabled)

Sets whether this view should display its own title.

void
setTitlePositionInterpolator(TimeInterpolator interpolator)

Sets the interpolator to use when animating the title position from collapsed to expanded and vice versa.

void
setVisibility(int visibility)

Protected methods

boolean
checkLayoutParams(LayoutParams p)
boolean
drawChild(Canvas canvas, View child, long drawingTime)
void
CollapsingToolbarLayout.LayoutParams
LayoutParams
generateLayoutParams(LayoutParams p)
void
void
onConfigurationChanged(Configuration newConfig)
void
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onSizeChanged(int w, int h, int oldw, int oldh)
boolean
verifyDrawable(Drawable who)

Constants

TITLE_COLLAPSE_MODE_FADE

public static final int TITLE_COLLAPSE_MODE_FADE = 1

The expanded title will fade out and translate, and the collapsed title will fade in.

TITLE_COLLAPSE_MODE_SCALE

public static final int TITLE_COLLAPSE_MODE_SCALE = 0

The expanded title will continuously scale and translate to its final collapsed position.

Public fields

contentScrim

public Drawable contentScrim

expandedTitleSpacing

public int expandedTitleSpacing

scrimAnimationDuration

public long scrimAnimationDuration

scrimVisibleHeightTrigger

public int scrimVisibleHeightTrigger

statusBarScrim

public Drawable statusBarScrim

titleCollapseMode

public int titleCollapseMode

Public constructors

CollapsingToolbarLayout

public CollapsingToolbarLayout(Context context)

CollapsingToolbarLayout

public CollapsingToolbarLayout(Context context, AttributeSet attrs)

CollapsingToolbarLayout

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

Public methods

draw

public void draw(Canvas canvas)

generateLayoutParams

public LayoutParams generateLayoutParams(AttributeSet attrs)

getCollapsedSubtitleTextSize

public float getCollapsedSubtitleTextSize()

Returns the text size of the collapsed subtitle.

getCollapsedSubtitleTypeface

public Typeface getCollapsedSubtitleTypeface()

Returns the typeface used for the collapsed subtitle.

getCollapsedTitleGravity

public int getCollapsedTitleGravity()

Returns the horizontal and vertical alignment for titles when collapsed.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_collapsedTitleGravity

getCollapsedTitleTextSize

public float getCollapsedTitleTextSize()

Returns the text size of the collapsed title.

getCollapsedTitleTypeface

public Typeface getCollapsedTitleTypeface()

Returns the typeface used for the collapsed title.

getContentScrim

public Drawable getContentScrim()

Returns the drawable which is used for the foreground scrim.

ref R.styleable#CollapsingToolbarLayout_contentScrim

See also
setContentScrim

getExpandedSubtitleTextSize

public float getExpandedSubtitleTextSize()

Returns the text size of the expanded subtitle.

getExpandedSubtitleTypeface

public Typeface getExpandedSubtitleTypeface()

Returns the typeface used for the expanded subtitle.

getExpandedTitleGravity

public int getExpandedTitleGravity()

Returns the horizontal and vertical alignment for titles when expanded.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleGravity

getExpandedTitleMarginBottom

public int getExpandedTitleMarginBottom()

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginBottom

Returns
int

the bottom expanded title margin in pixels

getExpandedTitleMarginEnd

public int getExpandedTitleMarginEnd()

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginEnd

Returns
int

the ending expanded title margin in pixels

getExpandedTitleMarginStart

public int getExpandedTitleMarginStart()

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginStart

Returns
int

the starting expanded title margin in pixels

getExpandedTitleMarginTop

public int getExpandedTitleMarginTop()

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginTop

Returns
int

the top expanded title margin in pixels

getExpandedTitleSpacing

public int getExpandedTitleSpacing()

Returns the spacing between the expanded title and subtitle in pixels

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleSpacing

getExpandedTitleTextSize

public float getExpandedTitleTextSize()

Returns the text size of the expanded title.

getExpandedTitleTypeface

public Typeface getExpandedTitleTypeface()

Returns the typeface used for the expanded title.

getHyphenationFrequency

public int getHyphenationFrequency()

Gets the hyphenation frequency of the title text, or -1 if not set. Experimental Feature.

getLineCount

public int getLineCount()

Gets the current number of lines of the title text. Experimental Feature.

getLineSpacingAdd

public float getLineSpacingAdd()

Gets the line spacing addition of the title text, or -1 if not set. Experimental Feature.

getLineSpacingMultiplier

public float getLineSpacingMultiplier()

Gets the line spacing multiplier of the title text, or -1 if not set. Experimental Feature.

getMaxLines

public int getMaxLines()

Gets the maximum number of lines to display in the expanded state. Experimental Feature.

getScrimAnimationDuration

public long getScrimAnimationDuration()

Returns the duration in milliseconds used for scrim visibility animations.

getScrimVisibleHeightTrigger

public int getScrimVisibleHeightTrigger()

Returns the amount of visible height in pixels used to define when to trigger a scrim visibility change.

getStatusBarScrim

public Drawable getStatusBarScrim()

Returns the drawable which is used for the status bar scrim.

ref R.styleable#CollapsingToolbarLayout_statusBarScrim

getSubtitle

public CharSequence getSubtitle()

Returns the subtitle currently being displayed by this view. If the subtitle is not enabled, then this will return null.

ref R.styleable#CollapsingToolbarLayout_subtitle

getTitle

public CharSequence getTitle()

Returns the title currently being displayed by this view. If the title is not enabled, then this will return null.

ref R.styleable#CollapsingToolbarLayout_title

getTitleCollapseMode

public int getTitleCollapseMode()

Returns the current title collapse mode.

ref R.styleable#CollapsingToolbarLayout_titleCollapseMode

getTitlePositionInterpolator

public TimeInterpolator getTitlePositionInterpolator()

Returns the interpolator being used to animate the title position from collapsed to expanded and vice versa.

getTitleTextEllipsize

public TruncateAt getTitleTextEllipsize()

Get ellipsizing currently applied on the title text.

isExtraMultilineHeightEnabled

public boolean isExtraMultilineHeightEnabled()

Gets whether extra height should be added when the title text spans across multiple lines. Experimental Feature.

isForceApplySystemWindowInsetTop

public boolean isForceApplySystemWindowInsetTop()

Gets whether the top system window inset should be respected regardless of what the layout_height of the CollapsingToolbarLayout is set to. Experimental Feature.

isRtlTextDirectionHeuristicsEnabled

public boolean isRtlTextDirectionHeuristicsEnabled()

Gets whether TextDirectionHeuristics should be used to determine whether the title text is RTL. Experimental Feature.

isTitleEnabled

public boolean isTitleEnabled()

Returns whether this view is currently displaying its own title.

ref R.styleable#CollapsingToolbarLayout_titleEnabled

See also
setTitleEnabled

setCollapsedSubtitleTextAppearance

public void setCollapsedSubtitleTextAppearance(int resId)

Sets the text color and size for the collapsed subtitle from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_collapsedSubtitleTextAppearance

setCollapsedSubtitleTextColor

public void setCollapsedSubtitleTextColor(int color)

Sets the text color of the collapsed subtitle.

Parameters
int color

The new text color in ARGB format

setCollapsedSubtitleTextColor

public void setCollapsedSubtitleTextColor(ColorStateList colors)

Sets the text colors of the collapsed subtitle.

Parameters
ColorStateList colors

ColorStateList containing the new text colors

setCollapsedSubtitleTextSize

public void setCollapsedSubtitleTextSize(float textSize)

Sets the text size of the collapsed subtitle.

Parameters
float textSize

The text size of the collapsed subtitle.

setCollapsedSubtitleTypeface

public void setCollapsedSubtitleTypeface(Typeface typeface)

Set the typeface to use for the collapsed subtitle.

Parameters
Typeface typeface

typeface to use, or null to use the default.

setCollapsedTitleGravity

public void setCollapsedTitleGravity(int gravity)

Sets the horizontal alignment of the collapsed titles and the vertical gravity that will be used when there is extra space in the collapsed bounds beyond what is required for the title itself.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_collapsedTitleGravity

setCollapsedTitleTextAppearance

public void setCollapsedTitleTextAppearance(int resId)

Sets the text color and size for the collapsed title from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_collapsedTitleTextAppearance

setCollapsedTitleTextColor

public void setCollapsedTitleTextColor(int color)

Sets the text color of the collapsed title.

Parameters
int color

The new text color in ARGB format

setCollapsedTitleTextColor

public void setCollapsedTitleTextColor(ColorStateList colors)

Sets the text colors of the collapsed title.

Parameters
ColorStateList colors

ColorStateList containing the new text colors

setCollapsedTitleTextSize

public void setCollapsedTitleTextSize(float textSize)

Sets the text size of the collapsed title.

Parameters
float textSize

The text size of the collapsed title.

setCollapsedTitleTypeface

public void setCollapsedTitleTypeface(Typeface typeface)

Set the typeface to use for the collapsed title.

Parameters
Typeface typeface

typeface to use, or null to use the default.

setContentScrim

public void setContentScrim(Drawable drawable)

Set the drawable to use for the content scrim from resources. Providing null will disable the scrim functionality.

ref R.styleable#CollapsingToolbarLayout_contentScrim

Parameters
Drawable drawable

the drawable to display

See also
getContentScrim

setContentScrimColor

public void setContentScrimColor(int color)

Set the color to use for the content scrim.

ref R.styleable#CollapsingToolbarLayout_contentScrim

Parameters
int color

the color to display

See also
getContentScrim

setContentScrimResource

public void setContentScrimResource(int resId)

Set the drawable to use for the content scrim from resources.

ref R.styleable#CollapsingToolbarLayout_contentScrim

Parameters
int resId

drawable resource id

See also
getContentScrim

setExpandedSubtitleColor

public void setExpandedSubtitleColor(int color)

Sets the text color of the expanded subtitle.

Parameters
int color

The new text color in ARGB format

setExpandedSubtitleTextAppearance

public void setExpandedSubtitleTextAppearance(int resId)

Sets the text color and size for the expanded subtitle from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedSubtitleTextAppearance

setExpandedSubtitleTextColor

public void setExpandedSubtitleTextColor(ColorStateList colors)

Sets the text colors of the expanded subtitle.

Parameters
ColorStateList colors

ColorStateList containing the new text colors

setExpandedSubtitleTextSize

public void setExpandedSubtitleTextSize(float textSize)

Sets the text size of the expanded subtitle.

Parameters
float textSize

The text size of the expanded subtitle.

setExpandedSubtitleTypeface

public void setExpandedSubtitleTypeface(Typeface typeface)

Set the typeface to use for the expanded subtitle.

Parameters
Typeface typeface

typeface to use, or null to use the default.

setExpandedTitleColor

public void setExpandedTitleColor(int color)

Sets the text color of the expanded title.

Parameters
int color

The new text color in ARGB format

setExpandedTitleGravity

public void setExpandedTitleGravity(int gravity)

Sets the horizontal alignment of the expanded titles and the vertical gravity that will be used when there is extra space in the expanded bounds beyond what is required for the title itself.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleGravity

setExpandedTitleMargin

public void setExpandedTitleMargin(int start, int top, int end, int bottom)

Sets the expanded title margins.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMargin

Parameters
int start

the starting title margin in pixels

int top

the top title margin in pixels

int end

the ending title margin in pixels

int bottom

the bottom title margin in pixels

setExpandedTitleMarginBottom

public void setExpandedTitleMarginBottom(int margin)

Sets the bottom expanded title margin in pixels.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginBottom

Parameters
int margin

the bottom title margin in pixels

setExpandedTitleMarginEnd

public void setExpandedTitleMarginEnd(int margin)

Sets the ending expanded title margin in pixels.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginEnd

Parameters
int margin

the ending title margin in pixels

setExpandedTitleMarginStart

public void setExpandedTitleMarginStart(int margin)

Sets the starting expanded title margin in pixels.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginStart

Parameters
int margin

the starting title margin in pixels

setExpandedTitleMarginTop

public void setExpandedTitleMarginTop(int margin)

Sets the top expanded title margin in pixels.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleMarginTop

Parameters
int margin

the top title margin in pixels

setExpandedTitleSpacing

public void setExpandedTitleSpacing(int titleSpacing)

Sets the spacing between the expanded title and subtitle.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleSpacing

Parameters
int titleSpacing

the spacing between the expanded title and subtitle in pixels

setExpandedTitleTextAppearance

public void setExpandedTitleTextAppearance(int resId)

Sets the text color and size for the expanded title from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_expandedTitleTextAppearance

setExpandedTitleTextColor

public void setExpandedTitleTextColor(ColorStateList colors)

Sets the text colors of the expanded title.

Parameters
ColorStateList colors

ColorStateList containing the new text colors

setExpandedTitleTextSize

public void setExpandedTitleTextSize(float textSize)

Sets the text size of the expanded title.

Parameters
float textSize

The text size of the expanded title.

setExpandedTitleTypeface

public void setExpandedTitleTypeface(Typeface typeface)

Set the typeface to use for the expanded title.

Parameters
Typeface typeface

typeface to use, or null to use the default.

setExtraMultilineHeightEnabled

public void setExtraMultilineHeightEnabled(boolean extraMultilineHeightEnabled)

Sets whether extra height should be added when the title text spans across multiple lines. Experimental Feature.

setForceApplySystemWindowInsetTop

public void setForceApplySystemWindowInsetTop(
    boolean forceApplySystemWindowInsetTop
)

Sets whether the top system window inset should be respected regardless of what the layout_height of the CollapsingToolbarLayout is set to. Experimental Feature.

setHyphenationFrequency

public void setHyphenationFrequency(int hyphenationFrequency)

Sets the hyphenation frequency of the title text. See setHyphenationFrequency. Experimental Feature.

setLineSpacingAdd

public void setLineSpacingAdd(float spacingAdd)

Sets the line spacing addition of the title text. See setLineSpacing. Experimental Feature.

setLineSpacingMultiplier

public void setLineSpacingMultiplier(float spacingMultiplier)

Sets the line spacing multiplier of the title text. See setLineSpacing. Experimental Feature.

setMaxLines

public void setMaxLines(int maxLines)

Sets the maximum number of lines to display in the expanded state. Experimental Feature.

setRtlTextDirectionHeuristicsEnabled

public void setRtlTextDirectionHeuristicsEnabled(
    boolean rtlTextDirectionHeuristicsEnabled
)

Sets whether TextDirectionHeuristics should be used to determine whether the title text is RTL. Experimental Feature.

setScrimAnimationDuration

public void setScrimAnimationDuration(long duration)

Set the duration used for scrim visibility animations.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_scrimAnimationDuration

Parameters
long duration

the duration to use in milliseconds

setScrimVisibleHeightTrigger

public void setScrimVisibleHeightTrigger(int height)

Set the amount of visible height in pixels used to define when to trigger a scrim visibility change.

If the visible height of this view is less than the given value, the scrims will be made visible, otherwise they are hidden.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_scrimVisibleHeightTrigger

Parameters
int height

value in pixels used to define when to trigger a scrim visibility change

setScrimsShown

public void setScrimsShown(boolean shown)

Set whether the content scrim and/or status bar scrim should be shown or not. Any change in the vertical scroll may overwrite this value. Any visibility change will be animated if this view has already been laid out.

Parameters
boolean shown

whether the scrims should be shown

setScrimsShown

public void setScrimsShown(boolean shown, boolean animate)

Set whether the content scrim and/or status bar scrim should be shown or not. Any change in the vertical scroll may overwrite this value.

Parameters
boolean shown

whether the scrims should be shown

boolean animate

whether to animate the visibility change

setStatusBarScrim

public void setStatusBarScrim(Drawable drawable)

Set the drawable to use for the status bar scrim from resources. Providing null will disable the scrim functionality.

This scrim is only shown when we have been given a top system inset.

ref R.styleable#CollapsingToolbarLayout_statusBarScrim

Parameters
Drawable drawable

the drawable to display

setStatusBarScrimColor

public void setStatusBarScrimColor(int color)

Set the color to use for the status bar scrim.

This scrim is only shown when we have been given a top system inset.

ref R.styleable#CollapsingToolbarLayout_statusBarScrim

Parameters
int color

the color to display

setStatusBarScrimResource

public void setStatusBarScrimResource(int resId)

Set the drawable to use for the status bar scrim from resources.

ref R.styleable#CollapsingToolbarLayout_statusBarScrim

Parameters
int resId

drawable resource id

setSubtitle

public void setSubtitle(CharSequence subtitle)

Sets the subtitle to be displayed by this view, if enabled.

ref R.styleable#CollapsingToolbarLayout_subtitle

setTitle

public void setTitle(CharSequence title)

Sets the title to be displayed by this view, if enabled.

ref R.styleable#CollapsingToolbarLayout_title

setTitleCollapseMode

public void setTitleCollapseMode(int titleCollapseMode)

Sets the title collapse mode which determines the effect used to collapse and expand the title text.

ref R.styleable#CollapsingToolbarLayout_titleCollapseMode

setTitleEllipsize

public void setTitleEllipsize(TruncateAt ellipsize)

Set ellipsizing on the title text.

ref R.styleable#CollapsingToolbarLayout_titleTextEllipsize

Parameters
TruncateAt ellipsize

type of ellipsis behavior

setTitleEnabled

public void setTitleEnabled(boolean enabled)

Sets whether this view should display its own title.

The title displayed by this view will shrink and grow based on the scroll offset.

ref R.styleable#CollapsingToolbarLayout_titleEnabled

setTitlePositionInterpolator

public void setTitlePositionInterpolator(TimeInterpolator interpolator)

Sets the interpolator to use when animating the title position from collapsed to expanded and vice versa.

ref com.google.android.material.R.styleable#CollapsingToolbarLayout_titlePositionInterpolator

Parameters
TimeInterpolator interpolator

the interpolator to use.

setVisibility

public void setVisibility(int visibility)

Protected methods

checkLayoutParams

protected boolean checkLayoutParams(LayoutParams p)

drawChild

protected boolean drawChild(Canvas canvas, View child, long drawingTime)

drawableStateChanged

protected void drawableStateChanged()

generateDefaultLayoutParams

protected CollapsingToolbarLayout.LayoutParams generateDefaultLayoutParams()

generateLayoutParams

protected LayoutParams generateLayoutParams(LayoutParams p)

onAttachedToWindow

protected void onAttachedToWindow()

onConfigurationChanged

protected void onConfigurationChanged(Configuration newConfig)

onDetachedFromWindow

protected void onDetachedFromWindow()

onLayout

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

onMeasure

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

onSizeChanged

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

verifyDrawable

protected boolean verifyDrawable(Drawable who)