O Google tem o compromisso de promover a igualdade racial para as comunidades negras. Saiba como.

CollapsingToolbarLayout

public class CollapsingToolbarLayout
extends FrameLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.google.android.material.appbar.CollapsingToolbarLayout


CollapsingToolbarLayout is a wrapper for ERROR(/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(CharSequence). 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(Drawable).

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(Drawable). 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 CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PARALLAX and CollapsingToolbarLayout.LayoutParams.setParallaxMultiplier(float).

Pinned position children

Child views can opt to be pinned in space globally. This is useful when implementing a collapsing as it allows the ERROR(/Toolbar) to be fixed in place even though this layout is moving. See CollapsingToolbarLayout.LayoutParams.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.

Summary

Nested classes

class CollapsingToolbarLayout.LayoutParams

 

XML attributes

CollapsingToolbarLayout_collapsedTitleGravity  
CollapsingToolbarLayout_collapsedTitleTextAppearance  
CollapsingToolbarLayout_contentScrim  
CollapsingToolbarLayout_expandedTitleGravity  
CollapsingToolbarLayout_expandedTitleMargin  
CollapsingToolbarLayout_expandedTitleMarginBottom  
CollapsingToolbarLayout_expandedTitleMarginEnd  
CollapsingToolbarLayout_expandedTitleMarginStart  
CollapsingToolbarLayout_expandedTitleMarginTop  
CollapsingToolbarLayout_expandedTitleTextAppearance  
CollapsingToolbarLayout_scrimAnimationDuration  
CollapsingToolbarLayout_scrimVisibleHeightTrigger  
CollapsingToolbarLayout_statusBarScrim  
CollapsingToolbarLayout_title  
CollapsingToolbarLayout_titleEnabled  
CollapsingToolbarLayout_toolbarId  

Inherited constants

Inherited fields

Public constructors

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

Public methods

void draw(Canvas canvas)
FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs)
int getCollapsedTitleGravity()

Returns the horizontal and vertical alignment for title when collapsed.

Typeface getCollapsedTitleTypeface()

Returns the typeface used for the collapsed title.

Drawable getContentScrim()

Returns the drawable which is used for the foreground scrim.

int getExpandedTitleGravity()

Returns the horizontal and vertical alignment for title when expanded.

int getExpandedTitleMarginBottom()
int getExpandedTitleMarginEnd()
int getExpandedTitleMarginStart()
int getExpandedTitleMarginTop()
Typeface getExpandedTitleTypeface()

Returns the typeface used for the expanded title.

int getMaxLines()

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

long getScrimAnimationDuration()

Returns the duration in milliseconds used for scrim visibility animations.

int getScrimVisibleHeightTrigger()

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

Drawable getStatusBarScrim()

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

CharSequence getTitle()

Returns the title currently being displayed by this view.

boolean isTitleEnabled()

Returns whether this view is currently displaying its own title.

void setCollapsedTitleGravity(int gravity)

Sets the horizontal alignment of the collapsed title 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 setCollapsedTitleTextAppearance(int resId)

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

void setCollapsedTitleTextColor(ColorStateList colors)

Sets the text colors of the collapsed title.

void setCollapsedTitleTextColor(int color)

Sets the text color 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 setContentScrimColor(int color)

Set the color to use for the content scrim.

void setContentScrimResource(int resId)

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

void setExpandedTitleColor(int color)

Sets the text color of the expanded title.

void setExpandedTitleGravity(int gravity)

Sets the horizontal alignment of the expanded title 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 setExpandedTitleMarginBottom(int margin)

Sets the bottom expanded title margin in pixels.

void setExpandedTitleMarginEnd(int margin)

Sets the ending expanded title margin in pixels.

void setExpandedTitleMarginStart(int margin)

Sets the starting expanded title margin in pixels.

void setExpandedTitleMarginTop(int margin)

Sets the top expanded title margin in pixels.

void setExpandedTitleTextAppearance(int resId)

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 setExpandedTitleTypeface(Typeface typeface)

Set the typeface to use for the expanded title.

void setMaxLines(int maxLines)

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

void setScrimAnimationDuration(long duration)

Set the duration used for scrim visibility animations.

void setScrimVisibleHeightTrigger(int height)

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

void setScrimsShown(boolean shown, boolean animate)

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

void setScrimsShown(boolean shown)

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 setStatusBarScrimColor(int color)

Set the color to use for the status bar scrim.

void setStatusBarScrimResource(int resId)

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

void setTitle(CharSequence title)

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

void setTitleEnabled(boolean enabled)

Sets whether this view should display its own title.

void setVisibility(int visibility)

Protected methods

boolean checkLayoutParams(ViewGroup.LayoutParams p)
boolean drawChild(Canvas canvas, View child, long drawingTime)
void drawableStateChanged()
CollapsingToolbarLayout.LayoutParams generateDefaultLayoutParams()
FrameLayout.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
void onAttachedToWindow()
void onDetachedFromWindow()
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)

Inherited methods

XML attributes

CollapsingToolbarLayout_collapsedTitleGravity

Related methods:

CollapsingToolbarLayout_collapsedTitleTextAppearance

Related methods:

CollapsingToolbarLayout_contentScrim

Related methods:

CollapsingToolbarLayout_expandedTitleGravity

Related methods:

CollapsingToolbarLayout_expandedTitleMargin

Related methods:

CollapsingToolbarLayout_expandedTitleMarginBottom

Related methods:

CollapsingToolbarLayout_expandedTitleMarginEnd

Related methods:

CollapsingToolbarLayout_expandedTitleMarginStart

Related methods:

CollapsingToolbarLayout_expandedTitleMarginTop

Related methods:

CollapsingToolbarLayout_expandedTitleTextAppearance

Related methods:

CollapsingToolbarLayout_scrimAnimationDuration

Related methods:

CollapsingToolbarLayout_scrimVisibleHeightTrigger

Related methods:

CollapsingToolbarLayout_statusBarScrim

Related methods:

CollapsingToolbarLayout_title

Related methods:

CollapsingToolbarLayout_titleEnabled

Related methods:

CollapsingToolbarLayout_toolbarId

Public constructors

CollapsingToolbarLayout

public CollapsingToolbarLayout (Context context)

Parameters
context Context

CollapsingToolbarLayout

public CollapsingToolbarLayout (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

CollapsingToolbarLayout

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

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

draw

public void draw (Canvas canvas)

Parameters
canvas Canvas

generateLayoutParams

public FrameLayout.LayoutParams generateLayoutParams (AttributeSet attrs)

Parameters
attrs AttributeSet

Returns
FrameLayout.LayoutParams

getCollapsedTitleGravity

public int getCollapsedTitleGravity ()

Returns the horizontal and vertical alignment for title when collapsed.

Related XML Attributes:

Returns
int

getCollapsedTitleTypeface

public Typeface getCollapsedTitleTypeface ()

Returns the typeface used for the collapsed title.

Returns
Typeface

getContentScrim

public Drawable getContentScrim ()

Returns the drawable which is used for the foreground scrim.

Related XML Attributes:

Returns
Drawable

getExpandedTitleGravity

public int getExpandedTitleGravity ()

Returns the horizontal and vertical alignment for title when expanded.

Related XML Attributes:

Returns
int

getExpandedTitleMarginBottom

public int getExpandedTitleMarginBottom ()

Related XML Attributes:

Returns
int the bottom expanded title margin in pixels

getExpandedTitleMarginEnd

public int getExpandedTitleMarginEnd ()

Related XML Attributes:

Returns
int the ending expanded title margin in pixels

getExpandedTitleMarginStart

public int getExpandedTitleMarginStart ()

Related XML Attributes:

Returns
int the starting expanded title margin in pixels

getExpandedTitleMarginTop

public int getExpandedTitleMarginTop ()

Related XML Attributes:

Returns
int the top expanded title margin in pixels

getExpandedTitleTypeface

public Typeface getExpandedTitleTypeface ()

Returns the typeface used for the expanded title.

Returns
Typeface

getMaxLines

public int getMaxLines ()

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

Returns
int

getScrimAnimationDuration

public long getScrimAnimationDuration ()

Returns the duration in milliseconds used for scrim visibility animations.

Returns
long

getScrimVisibleHeightTrigger

public int getScrimVisibleHeightTrigger ()

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

Returns
int

getStatusBarScrim

public Drawable getStatusBarScrim ()

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

Related XML Attributes:

Returns
Drawable

getTitle

public CharSequence getTitle ()

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

Related XML Attributes:

Returns
CharSequence

isTitleEnabled

public boolean isTitleEnabled ()

Returns whether this view is currently displaying its own title.

Related XML Attributes:

Returns
boolean

setCollapsedTitleGravity

public void setCollapsedTitleGravity (int gravity)

Sets the horizontal alignment of the collapsed title 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.

Related XML Attributes:

Parameters
gravity int

setCollapsedTitleTextAppearance

public void setCollapsedTitleTextAppearance (int resId)

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

Related XML Attributes:

Parameters
resId int

setCollapsedTitleTextColor

public void setCollapsedTitleTextColor (ColorStateList colors)

Sets the text colors of the collapsed title.

Parameters
colors ColorStateList: ColorStateList containing the new text colors

setCollapsedTitleTextColor

public void setCollapsedTitleTextColor (int color)

Sets the text color of the collapsed title.

Parameters
color int: The new text color in ARGB format

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.

Related XML Attributes:

Parameters
drawable Drawable: the drawable to display

See also:

setContentScrimColor

public void setContentScrimColor (int color)

Set the color to use for the content scrim.

Related XML Attributes:

Parameters
color int: the color to display

See also:

setContentScrimResource

public void setContentScrimResource (int resId)

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

Related XML Attributes:

Parameters
resId int: drawable resource id

See also:

setExpandedTitleColor

public void setExpandedTitleColor (int color)

Sets the text color of the expanded title.

Parameters
color int: The new text color in ARGB format

setExpandedTitleGravity

public void setExpandedTitleGravity (int gravity)

Sets the horizontal alignment of the expanded title 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.

Related XML Attributes:

Parameters
gravity int

setExpandedTitleMargin

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

Sets the expanded title margins.

Related XML Attributes:

Parameters
start int: the starting title margin in pixels

top int: the top title margin in pixels

end int: the ending title margin in pixels

bottom int: the bottom title margin in pixels

setExpandedTitleMarginBottom

public void setExpandedTitleMarginBottom (int margin)

Sets the bottom expanded title margin in pixels.

Related XML Attributes:

Parameters
margin int: the bottom title margin in pixels

setExpandedTitleMarginEnd

public void setExpandedTitleMarginEnd (int margin)

Sets the ending expanded title margin in pixels.

Related XML Attributes:

Parameters
margin int: the ending title margin in pixels

setExpandedTitleMarginStart

public void setExpandedTitleMarginStart (int margin)

Sets the starting expanded title margin in pixels.

Related XML Attributes:

Parameters
margin int: the starting title margin in pixels

setExpandedTitleMarginTop

public void setExpandedTitleMarginTop (int margin)

Sets the top expanded title margin in pixels.

Related XML Attributes:

Parameters
margin int: the top title margin in pixels

setExpandedTitleTextAppearance

public void setExpandedTitleTextAppearance (int resId)

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

Related XML Attributes:

Parameters
resId int

setExpandedTitleTextColor

public void setExpandedTitleTextColor (ColorStateList colors)

Sets the text colors of the expanded title.

Parameters
colors ColorStateList: ColorStateList containing the new text colors

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.

setMaxLines

public void setMaxLines (int maxLines)

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

Parameters
maxLines int

setScrimAnimationDuration

public void setScrimAnimationDuration (long duration)

Set the duration used for scrim visibility animations.

Related XML Attributes:

Parameters
duration long: 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.

Related XML Attributes:

Parameters
height int: value in pixels used to define when to trigger a scrim visibility change

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
shown boolean: whether the scrims should be shown

animate boolean: whether to animate the 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
shown boolean: whether the scrims should be shown

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.

Related XML Attributes:

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.

Related XML Attributes:

Parameters
color int: the color to display

setStatusBarScrimResource

public void setStatusBarScrimResource (int resId)

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

Related XML Attributes:

Parameters
resId int: drawable resource id

setTitle

public void setTitle (CharSequence title)

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

Related XML Attributes:

Parameters
title CharSequence

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.

Related XML Attributes:

Parameters
enabled boolean

setVisibility

public void setVisibility (int visibility)

Parameters
visibility int

Protected methods

checkLayoutParams

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams

Returns
boolean

drawChild

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

Parameters
canvas Canvas

child View

drawingTime long

Returns
boolean

drawableStateChanged

protected void drawableStateChanged ()

generateDefaultLayoutParams

protected CollapsingToolbarLayout.LayoutParams generateDefaultLayoutParams ()

Returns
CollapsingToolbarLayout.LayoutParams

generateLayoutParams

protected FrameLayout.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams

Returns
FrameLayout.LayoutParams

onAttachedToWindow

protected void onAttachedToWindow ()

onDetachedFromWindow

protected void onDetachedFromWindow ()

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

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

onSizeChanged

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

Parameters
w int

h int

oldw int

oldh int

verifyDrawable

protected boolean verifyDrawable (Drawable who)

Parameters
who Drawable

Returns
boolean