AppBarLayout

(SESL Variant) AppBarLayout is a vertical LinearLayout which implements many of the features of Material Design's app bar concept, specifically scrolling gestures and Samsung One UI (SESL) features.

In addition to standard Material app bar features, this SESL variant provides:

Core SESL Features

  • One UI Responsive Proportions: Dynamic height calculation for expanded app bar states relative to screen height, configurable via XML attributes (app:seslHeightProportion, app:seslUseCustomHeight) or programmatically using seslSetCustomHeightProportion and seslSetCustomHeight.
  • Immersive Offset Observers: Custom offset listeners (SeslOnImmOffsetChangedListener) to monitor vertical layout changes during immersive scroll.

SESL 9 Added Features

Children should provide their desired scrolling behavior through setScrollFlags and the associated layout xml attribute: app:layout_scrollFlags.

This view depends heavily on being used as a direct child within a CoordinatorLayout. If you use AppBarLayout within a different ViewGroup, most of its functionality will not work.

AppBarLayout also requires a separate scrolling sibling in order to know when to scroll. The binding is done through the ScrollingViewBehavior behavior class, meaning that you should set your scrolling view's behavior to be an instance of ScrollingViewBehavior. A string resource containing the full class name is available.

<androidx.coordinatorlayout.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <!-- Your scrolling content -->

    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.appbar.AppBarLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent">

        <androidx.appcompat.widget.Toolbar
                ...
                app:layout_scrollFlags="scroll|enterAlways"/>

        <com.google.android.material.tabs.TabLayout
                ...
                app:layout_scrollFlags="scroll|enterAlways"/>

    </com.google.android.material.appbar.AppBarLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

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

Constructors

Link copied to clipboard
constructor(@NonNull context: Context)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int)

Types

Link copied to clipboard
Interface definition for a callback to be invoked when the AppBarLayout's SESL state changes.
Link copied to clipboard
Interface definition for a callback to be invoked when an AppBarLayout's vertical offset changes.
Link copied to clipboard
open class Behavior : AppBarLayout.BaseBehavior<T>
The default Behavior for AppBarLayout.
Link copied to clipboard
abstract class ChildScrollEffect
An effect class that should be implemented and used by AppBarLayout children to be given effects when the AppBarLayout's offset changes.
Link copied to clipboard
A class which handles updating an AppBarLayout child, if marked with the app:layout_scrollEffectcompress, at each step in the AppBarLayout's offset animation.
Link copied to clipboard
Link copied to clipboard
Definition for a callback to be invoked when the lift on scroll elevation and background color change.
Link copied to clipboard
Definition for a callback to be invoked when the lift on scroll progress has changed.
Link copied to clipboard
Interface definition for a callback to be invoked when an AppBarLayout's vertical offset changes.
Link copied to clipboard
open class ScrollingViewBehavior : HeaderScrollingViewBehavior
Behavior which should be used by Views which can scroll vertically and support nested scrolling to automatically scroll any AppBarLayout siblings.
Link copied to clipboard
open class SeslAppbarState
Represents the current state of a SESL app bar.
Link copied to clipboard
Generic callback interface invoked when the AppBarLayout's vertical offset changes during immersive scrolling.
Link copied to clipboard
Interface definition for a callback to be invoked when an AppBarLayout's vertical offset changes during immersive scrolling.

Properties

Link copied to clipboard
Link copied to clipboard
State flag indicating the SESL app bar is collapsed.
Link copied to clipboard
State flag indicating the SESL app bar is expanded.
Link copied to clipboard
State flag indicating the SESL app bar is hidden.
Link copied to clipboard
State flag indicating the SESL app bar is idle.
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
Add a LiftOnScrollListener that will be called when the lift on scroll elevation and background color of this AppBarLayout change.
Link copied to clipboard
Add a LiftOnScrollProgressListener that will be called when the lift on scroll progress changes
Link copied to clipboard
Add a listener that will be called when the offset of this AppBarLayout changes.
Link copied to clipboard
open fun appBarStateChanged(oldState: Int, newState: Int)
Notifies registered AppBarStateChangedListener instances when app bar state changes.
Link copied to clipboard
Remove all previously added LiftOnScrollListeners.
Link copied to clipboard
Remove all previously added LiftOnScrollProgressListeners.
Link copied to clipboard
Link copied to clipboard
open fun draw(@NonNull canvas: Canvas)
Link copied to clipboard
Link copied to clipboard
open fun isLifted(): Boolean
Returns whether the AppBarLayout is in a lifted state or not.
Link copied to clipboard
Returns whether the AppBarLayout lifts on scroll or not.
Link copied to clipboard
Returns whether a forced expansion state has been requested.
Link copied to clipboard
@CanIgnoreReturnValue
open fun removeLiftOnScrollListener(@NonNull liftOnScrollListener: AppBarLayout.LiftOnScrollListener): Boolean
Remove a previously added LiftOnScrollListener.
Link copied to clipboard
Remove a previously added LiftOnScrollProgressListener.
Link copied to clipboard
open fun requestChildFocus(child: View, focused: View)
Link copied to clipboard
Adds an animator listener to receive callbacks during app bar offset animation transitions.
Link copied to clipboard
Adds a listener to be notified when the app bar state changes.
Link copied to clipboard
Sets whether nested scrolling gestures can initiate scrolling on this app bar.
Link copied to clipboard
Returns whether the AppBarLayout can currently transition to the hidden state.
Link copied to clipboard
Returns the SeslAppbarState object managing state flags for this app bar layout.
Link copied to clipboard
Returns the collapsed height of the app bar layout in pixels including top insets if immersive scroll is active.
Link copied to clipboard
Returns the current state flags of the AppBarLayout.
Link copied to clipboard
Returns the expanded height proportion ratio of the app bar relative to screen height.
Link copied to clipboard
Calculates the layout offset adjustment for views pinned directly below the toolbar.
Link copied to clipboard
Returns the proportion extra height of the AppBarLayout.
Link copied to clipboard
Returns the total calculated internal scroll range available for app bar scrolling.
Link copied to clipboard
open fun seslHasAppBarState(state: Int): Boolean
Link copied to clipboard
Internal check to determine whether an active nested fling is moving upwards.
Link copied to clipboard
Internal setter to allow or restrict state transition to hidden state.
Link copied to clipboard
Returns whether nested scrolling gestures can initiate scrolling on this app bar.
Link copied to clipboard
Returns whether the AppBarLayout is allowed to transition into the hidden state.
Link copied to clipboard
Link copied to clipboard
open fun seslIsHided(): Boolean
Returns whether the AppBarLayout is currently in the hidden state.
Link copied to clipboard
Returns whether the AppBarLayout is in the lift-hided state.
Link copied to clipboard
Removes a previously added app bar state changed listener.
Link copied to clipboard
Sets whether the AppBarLayout is allowed to transition into the hidden state.
open fun seslSetAllowStateToHide(allow: Boolean, requested: Boolean)
Sets whether the AppBarLayout is allowed to transition into the hidden state, along with specifying the internal request state.
Link copied to clipboard
open fun seslSetCollapsedHeight(height: Float)
Sets the collapsed height of the app bar layout in pixels.
Link copied to clipboard
open fun seslSetCustomHeight(height: Int)
Sets a custom pixel height for the expanded app bar.
Link copied to clipboard
open fun seslSetCustomHeightProportion(enabled: Boolean, @FloatRange(from = 0, to = 1) proportion: Float)
Sets custom height proportion for the expanded app bar relative to screen height.
Link copied to clipboard
open fun seslSetExpanded(expanded: Boolean)
Link copied to clipboard
open fun seslSetHide()
Requests the AppBarLayout to transition to the hidden state with animation.
open fun seslSetHide(animate: Boolean)

open fun seslSetHide(animate: Boolean, forceHide: Boolean)
Requests the AppBarLayout to transition to the hidden state.
Link copied to clipboard
open fun seslSetIsMouse(isMouse: Boolean)
Link copied to clipboard
open fun seslSetLiftHided(liftHided: Boolean)
Sets the lift-hided state of the AppBarLayout.
Link copied to clipboard
open fun seslSetProportionExtraHeight(extraHeight: Int)
Sets the proportion extra height for the AppBarLayout.
Link copied to clipboard
open fun seslSetSuggestion(hasSuggestion: Boolean)
Configures whether the app bar contains suggestion content (such as search suggestions or contextual chips).
Link copied to clipboard
open fun seslSetTCScrollRange(range: Int)
Sets additional scroll range for tab container or custom scroll range calculations.
Link copied to clipboard
Forces the app bar layout into an expanded state, overriding user touch interactions.
Link copied to clipboard
Releases a previously requested forced expanded state.
Link copied to clipboard
open fun setBackground(background: Drawable)
Link copied to clipboard
open fun setElevation(elevation: Float)
Link copied to clipboard
open fun setExpanded(expanded: Boolean)
Sets whether this AppBarLayout is expanded or not, animating if it has already been laid out.
open fun setExpanded(expanded: Boolean, animate: Boolean)
Sets whether this AppBarLayout is expanded or not.
Link copied to clipboard
open fun setLiftable(liftable: Boolean): Boolean
Sets whether the AppBarLayout is liftable or not.
Link copied to clipboard
Sets whether the AppBarLayout lifted state corresponding to setLiftable and setLifted will be overridden manually.
Link copied to clipboard
open fun setLifted(lifted: Boolean): Boolean
Sets whether the AppBarLayout is in a lifted state or not.
Link copied to clipboard
open fun setLiftOnScroll(liftOnScroll: Boolean)
Sets whether the AppBarLayout lifts on scroll or not.
Link copied to clipboard
open fun setLiftOnScrollColor(@Nullable liftOnScrollColor: ColorStateList)
Sets the color of the AppBarLayout when it is fully lifted.
Link copied to clipboard
open fun setLiftOnScrollTargetView(@Nullable liftOnScrollTargetView: View)
Sets the view that the AppBarLayout should use to determine whether it should be lifted.
Link copied to clipboard
open fun setOrientation(orientation: Int)
Link copied to clipboard
Set the color to use for the status bar foreground.
Link copied to clipboard
Set the drawable to use for the status bar foreground from resources.
Link copied to clipboard
open fun setTargetElevation(elevation: Float)
Link copied to clipboard
Configures whether the AppBarLayout should use floating toolbar mode.
Link copied to clipboard
open fun setVisibility(visibility: Int)
Link copied to clipboard
Link copied to clipboard
Returns whether the AppBarLayout is using floating toolbar mode.