Toolbar


class Toolbar : ViewGroup, MenuHost


A standard toolbar for use within application content.

A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. An application may choose to designate a Toolbar as the action bar for an Activity using the setSupportActionBar() method.

Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar may contain a combination of the following optional elements:

  • A navigation button. This may be an Up arrow, navigation menu toggle, close, collapse, done or another glyph of the app's choosing. This button should always be used to access other navigational destinations within the container of the Toolbar and its signified content or otherwise leave the current context signified by the Toolbar. The navigation button is vertically aligned within the Toolbar's minimum height, if set.
  • A branded logo image. This may extend to the height of the bar and can be arbitrarily wide.
  • A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.
  • One or more custom views. The application may add arbitrary child views to the Toolbar. They will appear at this position within the layout. If a child view's LayoutParams indicates a Gravity value of CENTER_HORIZONTAL the view will attempt to center within the available space remaining in the Toolbar after all other elements have been measured.
  • An action menu. The menu of actions will pin to the end of the Toolbar offering a few frequent, important or typical actions along with an optional overflow menu for additional actions. Action buttons are vertically aligned within the Toolbar's minimum height, if set.

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

buttonGravitycollapseContentDescriptioncollapseIconcontentInsetEndcontentInsetLeftcontentInsetRightcontentInsetStartcontentInsetStartWithNavigationcontentInsetEndWithActionsgravitylogologoDescriptionmaxButtonHeightnavigationContentDescriptionnavigationIconpopupThemesubtitlesubtitleTextAppearancesubtitleTextColortitletitleMargintitleMarginBottomtitleMarginEndtitleMarginStarttitleMarginToptitleTextAppearancetitleTextColormenu

Summary

Nested types

Layout information for child views of Toolbars.

Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners.

Public constructors

Toolbar(context: Context)
Toolbar(context: Context, attrs: AttributeSet?)
Toolbar(context: Context, attrs: AttributeSet?, defStyleAttr: Int)

Public functions

Unit

Adds the given MenuProvider to this MenuHost.

Unit

Adds the given MenuProvider to this MenuHost.

Unit
@MainThread
addMenuProvider(
    provider: MenuProvider,
    owner: LifecycleOwner,
    state: Lifecycle.State
)

Adds the given MenuProvider to this MenuHost once the given LifecycleOwner reaches the given Lifecycle.State.

Unit

Collapse a currently expanded action view.

Unit

Dismiss all currently showing popup menus, including overflow or submenus.

Toolbar.LayoutParams!
CharSequence?
@Attribute(value = "androidx.appcompat:collapseContentDescription")
getCollapseContentDescription()

Retrieve the currently configured content description for the collapse button view.

Drawable?
@Attribute(value = "androidx.appcompat:collapseIcon")
getCollapseIcon()

Return the current drawable used as the collapse icon.

Int
@Attribute(value = "androidx.appcompat:contentInsetEnd")
getContentInsetEnd()

Gets the ending content inset for this toolbar.

Int
@Attribute(value = "androidx.appcompat:contentInsetEndWithActions")
getContentInsetEndWithActions()

Gets the end content inset to use when action buttons are present.

Int
@Attribute(value = "androidx.appcompat:contentInsetLeft")
getContentInsetLeft()

Gets the left content inset for this toolbar.

Int
@Attribute(value = "androidx.appcompat:contentInsetRight")
getContentInsetRight()

Gets the right content inset for this toolbar.

Int
@Attribute(value = "androidx.appcompat:contentInsetStart")
getContentInsetStart()

Gets the starting content inset for this toolbar.

Int
@Attribute(value = "androidx.appcompat:contentInsetStartWithNavigation")
getContentInsetStartWithNavigation()

Gets the start content inset to use when a navigation button is present.

Int

Gets the content inset that will be used on the ending side of the bar in the current toolbar configuration.

Int

Gets the content inset that will be used on the left side of the bar in the current toolbar configuration.

Int

Gets the content inset that will be used on the right side of the bar in the current toolbar configuration.

Int

Gets the content inset that will be used on the starting side of the bar in the current toolbar configuration.

Drawable!
@Attribute(value = "androidx.appcompat:logo")
getLogo()

Return the current logo drawable.

CharSequence!
@Attribute(value = "androidx.appcompat:logoDescription")
getLogoDescription()

Return the description of the toolbar's logo.

Menu!
@Attribute(value = "androidx.appcompat:menu")
getMenu()

Return the Menu shown in the toolbar.

CharSequence?
@Attribute(value = "androidx.appcompat:navigationContentDescription")
getNavigationContentDescription()

Retrieve the currently configured content description for the navigation button view.

Drawable?
@Attribute(value = "androidx.appcompat:navigationIcon")
getNavigationIcon()

Return the current drawable used as the navigation icon.

Drawable?

Return the current drawable used as the overflow icon.

@StyleRes Int
@Attribute(value = "androidx.appcompat:popupTheme")
getPopupTheme()
CharSequence!
@Attribute(value = "androidx.appcompat:subtitle")
getSubtitle()

Return the subtitle of this toolbar.

CharSequence!
@Attribute(value = "androidx.appcompat:title")
getTitle()

Returns the title of this toolbar.

Int
@Attribute(value = "androidx.appcompat:titleMarginBottom")
getTitleMarginBottom()
Int
@Attribute(value = "androidx.appcompat:titleMarginEnd")
getTitleMarginEnd()
Int
@Attribute(value = "androidx.appcompat:titleMarginStart")
getTitleMarginStart()
Int
@Attribute(value = "androidx.appcompat:titleMarginTop")
getTitleMarginTop()
Boolean

Check whether this Toolbar is currently hosting an expanded action view.

Boolean

Hide the overflow items from the associated menu.

Unit

Inflate a menu resource into this toolbar.

Unit

Invalidates the to ensure that what is displayed matches the current internal state of the menu.

Boolean

Returns whether the toolbar will attempt to register its own OnBackInvokedCallback in supported configurations to handle collapsing expanded action items when a back invocation occurs.

Boolean

Check whether the overflow menu is currently showing.

Boolean
Unit
onRtlPropertiesChanged(layoutDirection: Int)
Boolean
Unit

Removes the given MenuProvider from this MenuHost.

Unit

Sets whether the toolbar will attempt to register its own OnBackInvokedCallback in supported configurations to handle collapsing expanded action items when a back invocation occurs.

Unit

Set a content description for the collapse button if one is present.

Unit

Set a content description for the collapse button if one is present.

Unit

Set the icon to use for the toolbar's collapse button.

Unit

Set the icon to use for the toolbar's collapse button.

Unit
setContentInsetEndWithActions(insetEndWithActions: Int)

Sets the start content inset to use when action buttons are present.

Unit
setContentInsetStartWithNavigation(insetStartWithNavigation: Int)

Sets the start content inset to use when a navigation button is present.

Unit
setContentInsetsAbsolute(contentInsetLeft: Int, contentInsetRight: Int)

Sets the content insets for this toolbar.

Unit
setContentInsetsRelative(contentInsetStart: Int, contentInsetEnd: Int)

Sets the content insets for this toolbar relative to layout direction.

Unit
setLogo(drawable: Drawable!)

Set a logo drawable.

Unit

Set a logo drawable from a resource id.

Unit

Set a description of the toolbar's logo.

Unit

Set a description of the toolbar's logo.

Unit

Set a content description for the navigation button if one is present.

Unit

Set a content description for the navigation button if one is present.

Unit

Set the icon to use for the toolbar's navigation button.

Unit

Set the icon to use for the toolbar's navigation button.

Unit

Set a listener to respond to navigation events.

Unit

Set a listener to respond to menu item click events.

Unit

Set the icon to use for the overflow button.

Unit

Specifies the theme to use when inflating popup menus.

Unit

Set the subtitle of this toolbar.

Unit

Set the subtitle of this toolbar.

Unit

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

Unit

Sets the text color of the subtitle, if present.

Unit

Sets the text color of the subtitle, if present.

Unit

Set the title of this toolbar.

Unit

Set the title of this toolbar.

Unit
setTitleMargin(start: Int, top: Int, end: Int, bottom: Int)

Sets the title margin.

Unit

Sets the bottom title margin in pixels.

Unit

Sets the ending title margin in pixels.

Unit

Sets the starting title margin in pixels.

Unit

Sets the top title margin in pixels.

Unit

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

Unit

Sets the text color of the title, if present.

Unit

Sets the text color of the title, if present.

Boolean

Show the overflow items from the associated menu.

Extension functions

Unit
Toolbar.setupWithNavController(
    navController: NavController,
    configuration: AppBarConfiguration
)

Sets up a Toolbar for use with a NavController.

Unit
Toolbar.setupWithNavController(
    navController: NavController,
    drawerLayout: DrawerLayout?
)

Sets up a Toolbar for use with a NavController.

Inherited Constants

From android.view.View
const Int
const Int
const Int
const Int
const Int
const Int
const Property<View!, Float!>!
const Int
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
const String!
const String!
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
const String!
const String!
const String!
const String!
const String!
const String!
const String!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int
const Int
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
GONE = 8
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
KEEP_SCREEN_ON = 67108864
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
NO_ID = -1
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const String!
VIEW_LOG_TAG = "View"
const Int
const IntArray<Int>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
From android.view.ViewGroup
const Int
const Int
const Int
const Int
const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

Inherited functions

From android.view.View
Unit
Unit
Unit
ViewPropertyAnimator!
Unit
Unit
Boolean
Unit
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Unit
Unit
Boolean
Unit
Unit
java-static Int
combineMeasuredStates(curState: Int, newState: Int)
Int
Int
Int
Unit
WindowInsets!
computeSystemWindowInsets(in: WindowInsets!, outLocalInsets: Rect!)
Int
Int
Int
AccessibilityNodeInfo!
Unit
Unit

This function is deprecated.

Boolean
Boolean
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)
Boolean
dispatchNestedPreFling(velocityX: Float, velocityY: Float)
Boolean
dispatchNestedPrePerformAccessibilityAction(
    action: Int,
    arguments: Bundle!
)
Boolean
dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray!,
    offsetInWindow: IntArray!
)
Boolean
dispatchNestedScroll(
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int,
    offsetInWindow: IntArray!
)
Boolean
Unit
draw(canvas: Canvas!)
Unit
OnBackInvokedDispatcher!
T!
<T : View?> findViewById(id: Int)
T!
<T : View?> findViewWithTag(tag: Any!)
Boolean

This function is deprecated.

Unit
forceHasOverlappingRendering(hasOverlappingRendering: Boolean)
Unit
Unit
generateDisplayHash(
    hashAlgorithm: String!,
    bounds: Rect!,
    executor: Executor!,
    callback: DisplayHashResultCallback!
)
java-static Int
View.AccessibilityDelegate!
Int
AccessibilityNodeProvider!
CharSequence!
Int
Int
String!
String!
Float
Animation!
Matrix!
IBinder!
IntArray<Int>!
(Mutable)Map<Int!, Int!>!
Array<String!>!
AutofillId!
Int
AutofillValue!
Drawable!
BlendMode!
ColorStateList!
PorterDuff.Mode!
Int
Int
Float
Int
Float
Rect!
Boolean
getClipBounds(outRect: Rect!)
Boolean
ContentCaptureSession!
CharSequence!
Context!
ContextMenu.ContextMenuInfo!
Boolean
java-static Int
getDefaultSize(size: Int, measureSpec: Int)
Display!
IntArray<Int>!
Bitmap!

This function is deprecated.

Int

This function is deprecated.

Int

This function is deprecated.

Unit
getDrawingRect(outRect: Rect!)
Long
Float
Int
Boolean
Boolean
Int
ArrayList<View!>!
getFocusables(direction: Int)
Unit
Drawable!
Int
BlendMode!
ColorStateList!
PorterDuff.Mode!
Boolean
getGlobalVisibleRect(r: Rect!, globalOffset: Point!)
Handler!
Float
Float
Float
Float
Runnable!
Boolean
Int
Unit
getHitRect(outRect: Rect!)
Int
Int
Drawable!
Drawable!
Int
Int
Int
Int
Boolean
KeyEvent.DispatcherState!
Int
Int
Int
ViewGroup.LayoutParams!
Int
Float
Int
Boolean
Unit
Unit
Unit
Matrix!
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
View.OnFocusChangeListener!
Int
ViewOutlineProvider!
Int
Int
ViewOverlay!
Int
Int
Int
Int
Int
Int
ViewParent!
ViewParent!
Float
Float
PointerIcon!
(Mutable)List<Rect!>!
Array<String!>!
Resources!
Boolean
Int
Float
Int
AttachedSurfaceControl!
View!
WindowInsets!
Float
Float
Float
Float
Float
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
CharSequence!
StateListAnimator!
Int
Int
(Mutable)List<Rect!>!
Int

This function is deprecated.

Any!
Int
Int
CharSequence!
Int
Float
Int
TouchDelegate!
ArrayList<View!>!
Float
String!
Float
Float
Float
Long
Int
Int
Drawable!
Drawable!
Int
ViewTranslationResponse!
ViewTreeObserver!
Int
Int
Int
WindowId!
WindowInsetsController!
Int

This function is deprecated.

IBinder!
Int
Unit
Float
Float
Float
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
java-static View!
inflate(context: Context!, resource: Int, root: ViewGroup!)
Unit
invalidate(dirty: Rect!)

This function is deprecated.

Unit
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean

This function is deprecated.

Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
View!
keyboardNavigationClusterSearch(currentCluster: View!, direction: Int)
Unit
measure(widthMeasureSpec: Int, heightMeasureSpec: Int)
java-static IntArray<Int>!
mergeDrawableStates(baseState: IntArray!, additionalState: IntArray!)
Unit
Unit
Unit
Unit
WindowInsets!
Unit
Boolean
Boolean
Unit
Unit
InputConnection!
Unit
onCreateViewTranslationRequest(
    supportedFormats: IntArray!,
    requestsCollector: Consumer<ViewTranslationRequest!>!
)
Unit
onCreateVirtualViewTranslationRequests(
    virtualIds: LongArray!,
    supportedFormats: IntArray!,
    requestsCollector: Consumer<ViewTranslationRequest!>!
)
Unit
Boolean
Unit
onDraw(canvas: Canvas!)
Unit
Unit
Boolean
Unit
Unit
Unit
onFocusChanged(
    gainFocus: Boolean,
    direction: Int,
    previouslyFocusedRect: Rect!
)
Boolean
Unit
Unit
Unit
Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)
Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent!)
Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent!)
Boolean
onKeyPreIme(keyCode: Int, event: KeyEvent!)
Boolean
onKeyShortcut(keyCode: Int, event: KeyEvent!)
Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)
Unit
onOverScrolled(
    scrollX: Int,
    scrollY: Int,
    clampedX: Boolean,
    clampedY: Boolean
)
Unit
Unit
Unit
Unit
Unit
Unit
Unit
ContentInfo!
Unit
onScreenStateChanged(screenState: Int)
Unit
onScrollCaptureSearch(
    localVisibleRect: Rect!,
    windowOffset: Point!,
    targets: Consumer<ScrollCaptureTarget!>!
)
Unit
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int)
Boolean
onSetAlpha(alpha: Int)
Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)
Unit
Boolean
Unit
Unit
Unit
Unit
onVisibilityChanged(changedView: View!, visibility: Int)
Unit
onWindowFocusChanged(hasWindowFocus: Boolean)
Unit

This function is deprecated.

Unit
Boolean
overScrollBy(
    deltaX: Int,
    deltaY: Int,
    scrollX: Int,
    scrollY: Int,
    scrollRangeX: Int,
    scrollRangeY: Int,
    maxOverScrollX: Int,
    maxOverScrollY: Int,
    isTouchEvent: Boolean
)
Boolean
performAccessibilityAction(action: Int, arguments: Bundle!)
Boolean
Boolean
Boolean
performHapticFeedback(feedbackConstant: Int)
Boolean
ContentInfo!
Unit
playSoundEffect(soundConstant: Int)
Boolean
post(action: Runnable!)
Boolean
postDelayed(action: Runnable!, delayMillis: Long)
Unit
Unit
postInvalidateDelayed(delayMilliseconds: Long)
Unit
Unit
Unit
postOnAnimationDelayed(action: Runnable!, delayMillis: Long)
Unit
Unit
Boolean
Unit
Unit
Unit
Unit
Unit

This function is deprecated.

Boolean
Unit
Unit
Boolean
Unit
T!
<T : View?> requireViewById(id: Int)
Unit
java-static Int
resolveSize(size: Int, measureSpec: Int)
java-static Int
resolveSizeAndState(size: Int, measureSpec: Int, childMeasuredState: Int)
Unit
Unit
saveAttributeDataForStyleable(
    context: Context!,
    styleable: IntArray!,
    attrs: AttributeSet!,
    t: TypedArray!,
    defStyleAttr: Int,
    defStyleRes: Int
)
Unit
Unit
scheduleDrawable(who: Drawable!, what: Runnable!, when: Long)
Unit
scrollBy(x: Int, y: Int)
Unit
scrollTo(x: Int, y: Int)
Unit
Unit
Unit
setAccessibilityDataSensitive(accessibilityDataSensitive: Int)
Unit
Unit
Unit
Unit
setAccessibilityPaneTitle(accessibilityPaneTitle: CharSequence!)
Unit
Unit
Unit
setActivated(activated: Boolean)
Unit
setAllowClickWhenDisabled(clickableWhenDisabled: Boolean)
Unit
Unit
Unit
setAlpha(alpha: Float)
Unit
setAnimation(animation: Animation!)
Unit
Unit
Unit
setAutofillHints(autofillHints: Array<String!>!)
Unit
Unit
setBackground(background: Drawable!)
Unit
Unit

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
setBottom(bottom: Int)
Unit
Unit
setClickable(clickable: Boolean)
Unit
setClipBounds(clipBounds: Rect!)
Unit
setClipToOutline(clipToOutline: Boolean)
Unit
Unit
setContentDescription(contentDescription: CharSequence!)
Unit
setContextClickable(contextClickable: Boolean)
Unit
setDefaultFocusHighlightEnabled(defaultFocusHighlightEnabled: Boolean)
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit
setElevation(elevation: Float)
Unit
setEnabled(enabled: Boolean)
Unit
Unit
Unit
setFitsSystemWindows(fitSystemWindows: Boolean)
Unit
setFocusable(focusable: Boolean)
Unit
setFocusableInTouchMode(focusableInTouchMode: Boolean)
Unit
setFocusedByDefault(isFocusedByDefault: Boolean)
Unit
Unit
setForeground(foreground: Drawable!)
Unit
Unit
Unit
Unit
Unit
setHandwritingBoundsOffsets(
    offsetLeft: Float,
    offsetTop: Float,
    offsetRight: Float,
    offsetBottom: Float
)
Unit
Unit
setHapticFeedbackEnabled(hapticFeedbackEnabled: Boolean)
Unit
setHasTransientState(hasTransientState: Boolean)
Unit
setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled: Boolean)
Unit
setHorizontalScrollBarEnabled(horizontalScrollBarEnabled: Boolean)
Unit
Unit
Unit
setHovered(hovered: Boolean)
Unit
setId(id: Int)
Unit
Unit
Unit
Unit
setIsCredential(isCredential: Boolean)
Unit
setIsHandwritingDelegate(isHandwritingDelegate: Boolean)
Unit
setKeepScreenOn(keepScreenOn: Boolean)
Unit
Unit
Unit
Unit
setLayerType(layerType: Int, paint: Paint!)
Unit
setLayoutDirection(layoutDirection: Int)
Unit
Unit
setLeft(left: Int)
Unit
setLeftTopRightBottom(left: Int, top: Int, right: Int, bottom: Int)
Unit
setLongClickable(longClickable: Boolean)
Unit
setMeasuredDimension(measuredWidth: Int, measuredHeight: Int)
Unit
setMinimumHeight(minHeight: Int)
Unit
setMinimumWidth(minWidth: Int)
Unit
Unit
setNextClusterForwardId(nextClusterForwardId: Int)
Unit
setNextFocusDownId(nextFocusDownId: Int)
Unit
setNextFocusForwardId(nextFocusForwardId: Int)
Unit
setNextFocusLeftId(nextFocusLeftId: Int)
Unit
setNextFocusRightId(nextFocusRightId: Int)
Unit
setNextFocusUpId(nextFocusUpId: Int)
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
setOnReceiveContentListener(
    mimeTypes: Array<String!>!,
    listener: OnReceiveContentListener!
)
Unit
Unit

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
setOverScrollMode(overScrollMode: Int)
Unit
setPadding(left: Int, top: Int, right: Int, bottom: Int)
Unit
setPaddingRelative(start: Int, top: Int, end: Int, bottom: Int)
Unit
setPivotX(pivotX: Float)
Unit
setPivotY(pivotY: Float)
Unit
setPointerIcon(pointerIcon: PointerIcon!)
Unit
setPreferKeepClear(preferKeepClear: Boolean)
Unit
Unit
setPressed(pressed: Boolean)
Unit
setRenderEffect(renderEffect: RenderEffect!)
Unit
setRevealOnFocusHint(revealOnFocus: Boolean)
Unit
setRight(right: Int)
Unit
setRotation(rotation: Float)
Unit
setRotationX(rotationX: Float)
Unit
setRotationY(rotationY: Float)
Unit
Unit
Unit
setScaleX(scaleX: Float)
Unit
setScaleY(scaleY: Float)
Unit
setScreenReaderFocusable(screenReaderFocusable: Boolean)
Unit
setScrollBarDefaultDelayBeforeFade(
    scrollBarDefaultDelayBeforeFade: Int
)
Unit
setScrollBarFadeDuration(scrollBarFadeDuration: Int)
Unit
setScrollBarSize(scrollBarSize: Int)
Unit
Unit
Unit
Unit
setScrollContainer(isScrollContainer: Boolean)
Unit
setScrollIndicators(indicators: Int)
Unit
setScrollX(value: Int)
Unit
setScrollY(value: Int)
Unit
Unit
setSelected(selected: Boolean)
Unit
setSoundEffectsEnabled(soundEffectsEnabled: Boolean)
Unit
setStateDescription(stateDescription: CharSequence!)
Unit
Unit
Unit

This function is deprecated.

Unit
setTag(tag: Any!)
Unit
setTextAlignment(textAlignment: Int)
Unit
setTextDirection(textDirection: Int)
Unit
Unit
setTop(top: Int)
Unit
Unit
Unit
setTransitionName(transitionName: String!)
Unit
Unit
setTranslationX(translationX: Float)
Unit
setTranslationY(translationY: Float)
Unit
setTranslationZ(translationZ: Float)
Unit
setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled: Boolean)
Unit
setVerticalScrollBarEnabled(verticalScrollBarEnabled: Boolean)
Unit
Unit
Unit
Unit
Unit
setVisibility(visibility: Int)
Unit
setWillNotCacheDrawing(willNotCacheDrawing: Boolean)

This function is deprecated.

Unit
setWillNotDraw(willNotDraw: Boolean)
Unit
setX(x: Float)
Unit
setY(y: Float)
Unit
setZ(z: Float)
Boolean
ActionMode!
Unit
Boolean
startDrag(
    data: ClipData!,
    shadowBuilder: View.DragShadowBuilder!,
    myLocalState: Any!,
    flags: Int
)

This function is deprecated.

Boolean
startDragAndDrop(
    data: ClipData!,
    shadowBuilder: View.DragShadowBuilder!,
    myLocalState: Any!,
    flags: Int
)
Boolean
Unit
String!
Unit
Unit
Unit
Unit
Boolean
Boolean

This function is deprecated.

Boolean
From android.view.ViewGroup
Unit
Unit
addExtraDataToAccessibilityNodeInfo(
    info: AccessibilityNodeInfo!,
    extraDataKey: String!,
    arguments: Bundle!
)
Unit
addFocusables(views: ArrayList<View!>!, direction: Int, focusableMode: Int)
Unit
addKeyboardNavigationClusters(
    views: (Mutable)Collection<View!>!,
    direction: Int
)
Boolean
Unit
Unit
addView(child: View!)
Boolean
addViewInLayout(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Unit
attachLayoutAnimationParameters(
    child: View!,
    params: ViewGroup.LayoutParams!,
    index: Int,
    count: Int
)
Unit
attachViewToParent(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Unit
Boolean
Unit
Unit
childHasTransientStateChanged(
    child: View!,
    childHasTransientState: Boolean
)
Unit
Unit
Unit
Unit
Unit
debug(depth: Int)
Unit
Unit
Unit
detachViewsFromParent(start: Int, count: Int)
WindowInsets!
Boolean
Unit
Unit
dispatchCreateViewTranslationRequest(
    viewIds: (Mutable)Map<AutofillId!, LongArray!>!,
    supportedFormats: IntArray!,
    capability: TranslationCapability!,
    requests: (Mutable)List<ViewTranslationRequest!>!
)
Unit
Boolean
Unit
dispatchDraw(canvas: Canvas!)
Unit
Unit
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Unit
Unit
Unit
Unit
Unit
dispatchScrollCaptureSearch(
    localVisibleRect: Rect!,
    windowOffset: Point!,
    targets: Consumer<ScrollCaptureTarget!>!
)
Unit
Unit
Unit
Unit
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
dispatchUnhandledMove(focused: View!, direction: Int)
Unit
dispatchVisibilityChanged(changedView: View!, visibility: Int)
Unit
Unit
Unit
WindowInsets!
dispatchWindowInsetsAnimationProgress(
    insets: WindowInsets!,
    runningAnimations: (Mutable)List<WindowInsetsAnimation!>!
)
WindowInsetsAnimation.Bounds!
Unit

This function is deprecated.

Unit
Boolean
drawChild(canvas: Canvas!, child: View!, drawingTime: Long)
Unit
Unit
View!
OnBackInvokedDispatcher!
Unit
findViewsWithText(
    outViews: ArrayList<View!>!,
    text: CharSequence!,
    flags: Int
)
View!
focusSearch(focused: View!, direction: Int)
Unit
Boolean
CharSequence!
View!
getChildAt(index: Int)
Int
Int
getChildDrawingOrder(childCount: Int, drawingPosition: Int)
java-static Int
getChildMeasureSpec(spec: Int, padding: Int, childDimension: Int)
Boolean
Boolean
getChildVisibleRect(child: View!, r: Rect!, offset: Point!)
Boolean
Boolean
Int
View!
LayoutAnimationController!
Animation.AnimationListener!
Int
LayoutTransition!
Int
ViewGroupOverlay!
Int

This function is deprecated.

Boolean
Boolean
Boolean
Int
indexOfChild(child: View!)
Unit
invalidateChild(child: View!, dirty: Rect!)

This function is deprecated.

ViewParent!
invalidateChildInParent(location: IntArray!, dirty: Rect!)

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean
Boolean

This function is deprecated.

Boolean
Boolean
Boolean
Unit
Unit
layout(l: Int, t: Int, r: Int, b: Int)
Unit
measureChild(
    child: View!,
    parentWidthMeasureSpec: Int,
    parentHeightMeasureSpec: Int
)
Unit
measureChildWithMargins(
    child: View!,
    parentWidthMeasureSpec: Int,
    widthUsed: Int,
    parentHeightMeasureSpec: Int,
    heightUsed: Int
)
Unit
measureChildren(widthMeasureSpec: Int, heightMeasureSpec: Int)
Unit
notifySubtreeAccessibilityStateChanged(
    child: View!,
    source: View!,
    changeType: Int
)
Unit
offsetDescendantRectToMyCoords(descendant: View!, rect: Rect!)
Unit
offsetRectIntoDescendantCoords(descendant: View!, rect: Rect!)
IntArray<Int>!
Unit
onDescendantInvalidated(child: View!, target: View!)
Boolean
Boolean
Boolean
onNestedFling(
    target: View!,
    velocityX: Float,
    velocityY: Float,
    consumed: Boolean
)
Boolean
onNestedPreFling(target: View!, velocityX: Float, velocityY: Float)
Boolean
onNestedPrePerformAccessibilityAction(
    target: View!,
    action: Int,
    args: Bundle!
)
Unit
onNestedPreScroll(target: View!, dx: Int, dy: Int, consumed: IntArray!)
Unit
onNestedScroll(
    target: View!,
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int
)
Unit
onNestedScrollAccepted(child: View!, target: View!, axes: Int)
Boolean
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!)
Boolean
PointerIcon!
onResolvePointerIcon(event: MotionEvent!, pointerIndex: Int)
Boolean
onStartNestedScroll(child: View!, target: View!, nestedScrollAxes: Int)
Unit
Unit
onViewAdded(child: View!)
Unit
Unit
Unit
Unit
Unit
removeDetachedView(child: View!, animate: Boolean)
Unit
removeView(view: View!)
Unit
removeViewAt(index: Int)
Unit
Unit
removeViews(start: Int, count: Int)
Unit
removeViewsInLayout(start: Int, count: Int)
Unit
requestChildFocus(child: View!, focused: View!)
Boolean
requestChildRectangleOnScreen(
    child: View!,
    rectangle: Rect!,
    immediate: Boolean
)
Unit
Boolean
requestFocus(direction: Int, previouslyFocusedRect: Rect!)
Boolean
Unit
Boolean
Unit
Unit
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit

This function is deprecated.

Unit
setClipChildren(clipChildren: Boolean)
Unit
setClipToPadding(clipToPadding: Boolean)
Unit
Unit
Unit
Unit
setLayoutMode(layoutMode: Int)
Unit
Unit
Unit
Unit
setPersistentDrawingCache(drawingCacheToKeep: Int)

This function is deprecated.

Unit
Unit
setTouchscreenBlocksFocus(touchscreenBlocksFocus: Boolean)
Unit
setTransitionGroup(isTransitionGroup: Boolean)
Unit
Boolean
Boolean
showContextMenuForChild(originalView: View!)
ActionMode!
startActionModeForChild(
    originalView: View!,
    callback: ActionMode.Callback!
)
Unit
Unit
Unit
Unit

Public constructors

Toolbar

Added in 1.1.0
Toolbar(context: Context)

Toolbar

Added in 1.1.0
Toolbar(context: Context, attrs: AttributeSet?)

Toolbar

Added in 1.1.0
Toolbar(context: Context, attrs: AttributeSet?, defStyleAttr: Int)

Public functions

addMenuProvider

Added in 1.4.0
@MainThread
fun addMenuProvider(provider: MenuProvider): Unit

Adds the given MenuProvider to this MenuHost. If using this method, you must manually remove the provider when necessary.

Parameters
provider: MenuProvider

the MenuProvider to be added

addMenuProvider

Added in 1.4.0
@MainThread
fun addMenuProvider(provider: MenuProvider, owner: LifecycleOwner): Unit

Adds the given MenuProvider to this MenuHost. This MenuProvider will be removed once the given LifecycleOwner receives an Lifecycle.Event.ON_DESTROY event.

Parameters
provider: MenuProvider

the MenuProvider to be added

owner: LifecycleOwner

the Lifecycle owner whose state will determine the removal of the provider

addMenuProvider

Added in 1.4.0
@MainThread
fun addMenuProvider(
    provider: MenuProvider,
    owner: LifecycleOwner,
    state: Lifecycle.State
): Unit

Adds the given MenuProvider to this MenuHost once the given LifecycleOwner reaches the given Lifecycle.State. This MenuProvider will be removed once the given LifecycleOwner goes down from the given Lifecycle.State.

Parameters
provider: MenuProvider

the MenuProvider to be added

owner: LifecycleOwner

the Lifecycle owner whose state will be used for automated addition/removal

state: Lifecycle.State

the Lifecycle.State to check for automated addition/removal

collapseActionView

Added in 1.1.0
fun collapseActionView(): Unit

Collapse a currently expanded action view. If this Toolbar does not have an expanded action view this method has no effect.

An action view may be expanded either directly from the MenuItem it belongs to or by user action.

dismissPopupMenus

Added in 1.1.0
fun dismissPopupMenus(): Unit

Dismiss all currently showing popup menus, including overflow or submenus.

generateLayoutParams

Added in 1.1.0
fun generateLayoutParams(attrs: AttributeSet!): Toolbar.LayoutParams!

getCollapseContentDescription

Added in 1.1.0
@Attribute(value = "androidx.appcompat:collapseContentDescription")
fun getCollapseContentDescription(): CharSequence?

Retrieve the currently configured content description for the collapse button view. This will be used to describe the collapse action to users through mechanisms such as screen readers or tooltips.

Returns
CharSequence?

The collapse button's content description collapseContentDescription

getCollapseIcon

Added in 1.1.0
@Attribute(value = "androidx.appcompat:collapseIcon")
fun getCollapseIcon(): Drawable?

Return the current drawable used as the collapse icon.

Returns
Drawable?

The collapse icon drawable collapseIcon

getContentInsetEnd

Added in 1.1.0
@Attribute(value = "androidx.appcompat:contentInsetEnd")
fun getContentInsetEnd(): Int

Gets the ending content inset for this toolbar.

The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.

Returns
Int

The ending content inset for this toolbar

getContentInsetEndWithActions

Added in 1.1.0
@Attribute(value = "androidx.appcompat:contentInsetEndWithActions")
fun getContentInsetEndWithActions(): Int

Gets the end content inset to use when action buttons are present.

Different content insets are often called for when additional buttons are present in the toolbar, as well as at different toolbar sizes. The larger value of getContentInsetEnd and this value will be used during layout.

Returns
Int

the end content inset used when a menu has been set in pixels

getContentInsetLeft

Added in 1.1.0
@Attribute(value = "androidx.appcompat:contentInsetLeft")
fun getContentInsetLeft(): Int

Gets the left content inset for this toolbar.

The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.

Returns
Int

The left content inset for this toolbar

getContentInsetRight

Added in 1.1.0
@Attribute(value = "androidx.appcompat:contentInsetRight")
fun getContentInsetRight(): Int

Gets the right content inset for this toolbar.

The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.

Returns
Int

The right content inset for this toolbar

getContentInsetStart

Added in 1.1.0
@Attribute(value = "androidx.appcompat:contentInsetStart")
fun getContentInsetStart(): Int

Gets the starting content inset for this toolbar.

The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.

Returns
Int

The starting content inset for this toolbar

getContentInsetStartWithNavigation

Added in 1.1.0
@Attribute(value = "androidx.appcompat:contentInsetStartWithNavigation")
fun getContentInsetStartWithNavigation(): Int

Gets the start content inset to use when a navigation button is present.

Different content insets are often called for when additional buttons are present in the toolbar, as well as at different toolbar sizes. The larger value of getContentInsetStart and this value will be used during layout.

Returns
Int

the start content inset used when a navigation icon has been set in pixels

getCurrentContentInsetEnd

Added in 1.1.0
fun getCurrentContentInsetEnd(): Int

Gets the content inset that will be used on the ending side of the bar in the current toolbar configuration.

Returns
Int

the current content inset end in pixels

getCurrentContentInsetLeft

Added in 1.1.0
fun getCurrentContentInsetLeft(): Int

Gets the content inset that will be used on the left side of the bar in the current toolbar configuration.

Returns
Int

the current content inset left in pixels

getCurrentContentInsetRight

Added in 1.1.0
fun getCurrentContentInsetRight(): Int

Gets the content inset that will be used on the right side of the bar in the current toolbar configuration.

Returns
Int

the current content inset right in pixels

getCurrentContentInsetStart

Added in 1.1.0
fun getCurrentContentInsetStart(): Int

Gets the content inset that will be used on the starting side of the bar in the current toolbar configuration.

Returns
Int

the current content inset start in pixels

getLogo

Added in 1.1.0
@Attribute(value = "androidx.appcompat:logo")
fun getLogo(): Drawable!

Return the current logo drawable.

Returns
Drawable!

The current logo drawable

See also
setLogo
setLogo

getLogoDescription

Added in 1.1.0
@Attribute(value = "androidx.appcompat:logoDescription")
fun getLogoDescription(): CharSequence!

Return the description of the toolbar's logo.

Returns
CharSequence!

A description of the logo

getMenu

Added in 1.1.0
@Attribute(value = "androidx.appcompat:menu")
fun getMenu(): Menu!

Return the Menu shown in the toolbar.

Applications that wish to populate the toolbar's menu can do so from here. To use an XML menu resource, use inflateMenu.

Returns
Menu!

The toolbar's Menu menu

getNavigationContentDescription

Added in 1.1.0
@Attribute(value = "androidx.appcompat:navigationContentDescription")
fun getNavigationContentDescription(): CharSequence?

Retrieve the currently configured content description for the navigation button view. This will be used to describe the navigation action to users through mechanisms such as screen readers or tooltips.

Returns
CharSequence?

The navigation button's content description navigationContentDescription

getNavigationIcon

Added in 1.1.0
@Attribute(value = "androidx.appcompat:navigationIcon")
fun getNavigationIcon(): Drawable?

Return the current drawable used as the navigation icon.

Returns
Drawable?

The navigation icon drawable navigationIcon

getOverflowIcon

Added in 1.1.0
fun getOverflowIcon(): Drawable?

Return the current drawable used as the overflow icon.

Returns
Drawable?

The overflow icon drawable

getPopupTheme

Added in 1.1.0
@Attribute(value = "androidx.appcompat:popupTheme")
fun getPopupTheme(): @StyleRes Int
Returns
@StyleRes Int

resource identifier of the theme used to inflate popup menus, or 0 if menus are inflated against the toolbar theme

See also
setPopupTheme

getSubtitle

Added in 1.1.0
@Attribute(value = "androidx.appcompat:subtitle")
fun getSubtitle(): CharSequence!

Return the subtitle of this toolbar.

Returns
CharSequence!

The current subtitle

getTitle

Added in 1.1.0
@Attribute(value = "androidx.appcompat:title")
fun getTitle(): CharSequence!

Returns the title of this toolbar.

Returns
CharSequence!

The current title.

getTitleMarginBottom

Added in 1.1.0
@Attribute(value = "androidx.appcompat:titleMarginBottom")
fun getTitleMarginBottom(): Int
Returns
Int

the bottom title margin in pixels

getTitleMarginEnd

Added in 1.1.0
@Attribute(value = "androidx.appcompat:titleMarginEnd")
fun getTitleMarginEnd(): Int
Returns
Int

the ending title margin in pixels

getTitleMarginStart

Added in 1.1.0
@Attribute(value = "androidx.appcompat:titleMarginStart")
fun getTitleMarginStart(): Int
Returns
Int

the starting title margin in pixels

getTitleMarginTop

Added in 1.1.0
@Attribute(value = "androidx.appcompat:titleMarginTop")
fun getTitleMarginTop(): Int
Returns
Int

the top title margin in pixels

hasExpandedActionView

Added in 1.1.0
fun hasExpandedActionView(): Boolean

Check whether this Toolbar is currently hosting an expanded action view.

An action view may be expanded either directly from the MenuItem it belongs to or by user action. If the Toolbar has an expanded action view it can be collapsed using the collapseActionView method.

Returns
Boolean

true if the Toolbar has an expanded action view

hideOverflowMenu

Added in 1.1.0
fun hideOverflowMenu(): Boolean

Hide the overflow items from the associated menu.

Returns
Boolean

true if the menu was able to be hidden, false otherwise

inflateMenu

Added in 1.1.0
fun inflateMenu(resId: @MenuRes Int): Unit

Inflate a menu resource into this toolbar.

Inflate an XML menu resource into this toolbar. Existing items in the menu will not be modified or removed.

Parameters
resId: @MenuRes Int

ID of a menu resource to inflate menu

invalidateMenu

Added in 1.4.0
@MainThread
fun invalidateMenu(): Unit

Invalidates the to ensure that what is displayed matches the current internal state of the menu. This should be called whenever the state of the menu is changed, such as items being removed or disabled based on some user event. Only the items in the Menu that were provided by MenuProviders should be removed and repopulated, leaving all manually inflated menu items untouched, as they should continue to be managed manually.

isBackInvokedCallbackEnabled

Added in 1.6.0
fun isBackInvokedCallbackEnabled(): Boolean

Returns whether the toolbar will attempt to register its own OnBackInvokedCallback in supported configurations to handle collapsing expanded action items when a back invocation occurs.

isOverflowMenuShowing

Added in 1.1.0
fun isOverflowMenuShowing(): Boolean

Check whether the overflow menu is currently showing. This may not reflect a pending show operation in progress.

Returns
Boolean

true if the overflow menu is currently showing

onHoverEvent

fun onHoverEvent(ev: MotionEvent!): Boolean

onRtlPropertiesChanged

fun onRtlPropertiesChanged(layoutDirection: Int): Unit

onTouchEvent

fun onTouchEvent(ev: MotionEvent!): Boolean

removeMenuProvider

Added in 1.4.0
@MainThread
fun removeMenuProvider(provider: MenuProvider): Unit

Removes the given MenuProvider from this MenuHost.

Parameters
provider: MenuProvider

the MenuProvider to be removed

setBackInvokedCallbackEnabled

Added in 1.6.0
fun setBackInvokedCallbackEnabled(enabled: Boolean): Unit

Sets whether the toolbar will attempt to register its own OnBackInvokedCallback in supported configurations to handle collapsing expanded action items when a back invocation occurs.

This feature is only supported on SDK 33 and above for applications that have enabled back invocation callback handling.

Parameters
enabled: Boolean

true to attempt to register a back invocation callback in supported configurations or false to not automatically handle back invocations

setCollapseContentDescription

Added in 1.1.0
fun setCollapseContentDescription(description: CharSequence?): Unit

Set a content description for the collapse button if one is present. The content description will be read via screen readers or other accessibility systems to explain the action of the navigation button.

Parameters
description: CharSequence?

Content description to set, or null to clear the content description collapseContentDescription

setCollapseContentDescription

Added in 1.1.0
fun setCollapseContentDescription(resId: @StringRes Int): Unit

Set a content description for the collapse button if one is present. The content description will be read via screen readers or other accessibility systems to explain the action of the collapse button.

Parameters
resId: @StringRes Int

Resource ID of a content description string to set, or 0 to clear the description collapseContentDescription

setCollapseIcon

Added in 1.1.0
fun setCollapseIcon(icon: Drawable?): Unit

Set the icon to use for the toolbar's collapse button.

The collapse button appears at the start of the toolbar when an action view is present .

Parameters
icon: Drawable?

Drawable to set, may be null to use the default icon collapseIcon

setCollapseIcon

Added in 1.1.0
fun setCollapseIcon(resId: @DrawableRes Int): Unit

Set the icon to use for the toolbar's collapse button.

The collapse button appears at the start of the toolbar when an action view is present .

Parameters
resId: @DrawableRes Int

Resource ID of a drawable to set collapseIcon

setContentInsetEndWithActions

Added in 1.1.0
fun setContentInsetEndWithActions(insetEndWithActions: Int): Unit

Sets the start content inset to use when action buttons are present.

Different content insets are often called for when additional buttons are present in the toolbar, as well as at different toolbar sizes. The larger value of getContentInsetEnd and this value will be used during layout.

Parameters
insetEndWithActions: Int

the inset to use when a menu has been set in pixels

setContentInsetStartWithNavigation

Added in 1.1.0
fun setContentInsetStartWithNavigation(insetStartWithNavigation: Int): Unit

Sets the start content inset to use when a navigation button is present.

Different content insets are often called for when additional buttons are present in the toolbar, as well as at different toolbar sizes. The larger value of getContentInsetStart and this value will be used during layout.

Parameters
insetStartWithNavigation: Int

the inset to use when a navigation icon has been set in pixels

setContentInsetsAbsolute

Added in 1.1.0
fun setContentInsetsAbsolute(contentInsetLeft: Int, contentInsetRight: Int): Unit

Sets the content insets for this toolbar.

The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.

Parameters
contentInsetLeft: Int

Content inset for the toolbar's left edge

contentInsetRight: Int

Content inset for the toolbar's right edge

setContentInsetsRelative

Added in 1.1.0
fun setContentInsetsRelative(contentInsetStart: Int, contentInsetEnd: Int): Unit

Sets the content insets for this toolbar relative to layout direction.

The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.

Parameters
contentInsetStart: Int

Content inset for the toolbar starting edge

contentInsetEnd: Int

Content inset for the toolbar ending edge

setLogo

Added in 1.1.0
fun setLogo(drawable: Drawable!): Unit

Set a logo drawable.

This drawable should generally take the place of title text. The logo cannot be clicked. Apps using a logo should also supply a description using setLogoDescription.

Parameters
drawable: Drawable!

Drawable to use as a logo

setLogo

Added in 1.1.0
fun setLogo(resId: @DrawableRes Int): Unit

Set a logo drawable from a resource id.

This drawable should generally take the place of title text. The logo cannot be clicked. Apps using a logo should also supply a description using setLogoDescription.

Parameters
resId: @DrawableRes Int

ID of a drawable resource

setLogoDescription

Added in 1.1.0
fun setLogoDescription(description: CharSequence!): Unit

Set a description of the toolbar's logo.

This description will be used for accessibility or other similar descriptions of the UI.

Parameters
description: CharSequence!

Description to set

setLogoDescription

Added in 1.1.0
fun setLogoDescription(resId: @StringRes Int): Unit

Set a description of the toolbar's logo.

This description will be used for accessibility or other similar descriptions of the UI.

Parameters
resId: @StringRes Int

String resource id

setNavigationContentDescription

Added in 1.1.0
fun setNavigationContentDescription(description: CharSequence?): Unit

Set a content description for the navigation button if one is present. The content description will be read via screen readers or other accessibility systems to explain the action of the navigation button.

Parameters
description: CharSequence?

Content description to set, or null to clear the content description navigationContentDescription

setNavigationContentDescription

Added in 1.1.0
fun setNavigationContentDescription(resId: @StringRes Int): Unit

Set a content description for the navigation button if one is present. The content description will be read via screen readers or other accessibility systems to explain the action of the navigation button.

Parameters
resId: @StringRes Int

Resource ID of a content description string to set, or 0 to clear the description navigationContentDescription

setNavigationIcon

Added in 1.1.0
fun setNavigationIcon(icon: Drawable?): Unit

Set the icon to use for the toolbar's navigation button.

The navigation button appears at the start of the toolbar if present. Setting an icon will make the navigation button visible.

If you use a navigation icon you should also set a description for its action using setNavigationContentDescription. This is used for accessibility and tooltips.

Parameters
icon: Drawable?

Drawable to set, may be null to clear the icon navigationIcon

setNavigationIcon

Added in 1.1.0
fun setNavigationIcon(resId: @DrawableRes Int): Unit

Set the icon to use for the toolbar's navigation button.

The navigation button appears at the start of the toolbar if present. Setting an icon will make the navigation button visible.

If you use a navigation icon you should also set a description for its action using setNavigationContentDescription. This is used for accessibility and tooltips.

Parameters
resId: @DrawableRes Int

Resource ID of a drawable to set navigationIcon

setNavigationOnClickListener

Added in 1.1.0
fun setNavigationOnClickListener(listener: View.OnClickListener!): Unit

Set a listener to respond to navigation events.

This listener will be called whenever the user clicks the navigation button at the start of the toolbar. An icon must be set for the navigation button to appear.

Parameters
listener: View.OnClickListener!

Listener to set

setOnMenuItemClickListener

Added in 1.1.0
fun setOnMenuItemClickListener(listener: Toolbar.OnMenuItemClickListener!): Unit

Set a listener to respond to menu item click events.

This listener will be invoked whenever a user selects a menu item from the action buttons presented at the end of the toolbar or the associated overflow.

Parameters
listener: Toolbar.OnMenuItemClickListener!

Listener to set

setOverflowIcon

Added in 1.1.0
fun setOverflowIcon(icon: Drawable?): Unit

Set the icon to use for the overflow button.

Parameters
icon: Drawable?

Drawable to set, may be null to clear the icon

setPopupTheme

Added in 1.1.0
fun setPopupTheme(resId: @StyleRes Int): Unit

Specifies the theme to use when inflating popup menus. By default, uses the same theme as the toolbar itself.

Parameters
resId: @StyleRes Int

theme used to inflate popup menus

See also
getPopupTheme

setSubtitle

Added in 1.1.0
fun setSubtitle(resId: @StringRes Int): Unit

Set the subtitle of this toolbar.

Subtitles should express extended information about the current content.

Parameters
resId: @StringRes Int

String resource ID

setSubtitle

Added in 1.1.0
fun setSubtitle(subtitle: CharSequence!): Unit

Set the subtitle of this toolbar.

Subtitles should express extended information about the current content.

Parameters
subtitle: CharSequence!

Subtitle to set

setSubtitleTextAppearance

Added in 1.1.0
fun setSubtitleTextAppearance(context: Context!, resId: @StyleRes Int): Unit

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

setSubtitleTextColor

Added in 1.1.0
fun setSubtitleTextColor(color: ColorStateList): Unit

Sets the text color of the subtitle, if present.

Parameters
color: ColorStateList

The new text color

setSubtitleTextColor

Added in 1.1.0
fun setSubtitleTextColor(color: @ColorInt Int): Unit

Sets the text color of the subtitle, if present.

Parameters
color: @ColorInt Int

The new text color in 0xAARRGGBB format

setTitle

Added in 1.1.0
fun setTitle(resId: @StringRes Int): Unit

Set the title of this toolbar.

A title should be used as the anchor for a section of content. It should describe or name the content being viewed.

Parameters
resId: @StringRes Int

Resource ID of a string to set as the title

setTitle

Added in 1.1.0
fun setTitle(title: CharSequence!): Unit

Set the title of this toolbar.

A title should be used as the anchor for a section of content. It should describe or name the content being viewed.

Parameters
title: CharSequence!

Title to set

setTitleMargin

Added in 1.1.0
fun setTitleMargin(start: Int, top: Int, end: Int, bottom: Int): Unit

Sets the title margin.

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

setTitleMarginBottom

Added in 1.1.0
fun setTitleMarginBottom(margin: Int): Unit

Sets the bottom title margin in pixels.

Parameters
margin: Int

the bottom title margin in pixels

setTitleMarginEnd

Added in 1.1.0
fun setTitleMarginEnd(margin: Int): Unit

Sets the ending title margin in pixels.

Parameters
margin: Int

the ending title margin in pixels

setTitleMarginStart

Added in 1.1.0
fun setTitleMarginStart(margin: Int): Unit

Sets the starting title margin in pixels.

Parameters
margin: Int

the starting title margin in pixels

setTitleMarginTop

Added in 1.1.0
fun setTitleMarginTop(margin: Int): Unit

Sets the top title margin in pixels.

Parameters
margin: Int

the top title margin in pixels

setTitleTextAppearance

Added in 1.1.0
fun setTitleTextAppearance(context: Context!, resId: @StyleRes Int): Unit

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

setTitleTextColor

Added in 1.1.0
fun setTitleTextColor(color: ColorStateList): Unit

Sets the text color of the title, if present.

Parameters
color: ColorStateList

The new text color

setTitleTextColor

Added in 1.1.0
fun setTitleTextColor(color: @ColorInt Int): Unit

Sets the text color of the title, if present.

Parameters
color: @ColorInt Int

The new text color in 0xAARRGGBB format

showOverflowMenu

Added in 1.1.0
fun showOverflowMenu(): Boolean

Show the overflow items from the associated menu.

Returns
Boolean

true if the menu was able to be shown, false otherwise

Protected functions

checkLayoutParams

protected fun checkLayoutParams(p: ViewGroup.LayoutParams!): Boolean

generateDefaultLayoutParams

Added in 1.1.0
protected fun generateDefaultLayoutParams(): Toolbar.LayoutParams!

generateLayoutParams

Added in 1.1.0
protected fun generateLayoutParams(p: ViewGroup.LayoutParams!): Toolbar.LayoutParams!

onAttachedToWindow

protected fun onAttachedToWindow(): Unit

onDetachedFromWindow

protected fun onDetachedFromWindow(): Unit

onLayout

protected fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int): Unit

onMeasure

protected fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

onRestoreInstanceState

protected fun onRestoreInstanceState(state: Parcelable!): Unit

onSaveInstanceState

protected fun onSaveInstanceState(): Parcelable!

Extension functions

setupWithNavController

fun Toolbar.setupWithNavController(
    navController: NavController,
    configuration: AppBarConfiguration = AppBarConfiguration(navController.graph)
): Unit

Sets up a Toolbar for use with a NavController.

By calling this method, the title in the Toolbar will automatically be updated when the destination changes (assuming there is a valid label).

The AppBarConfiguration you provide controls how the Navigation button is displayed and what action is triggered when the Navigation button is tapped.

This method will call NavController.navigateUp when the navigation icon is clicked.

Parameters
navController: NavController

The NavController whose navigation actions will be reflected in the title of the Toolbar.

configuration: AppBarConfiguration = AppBarConfiguration(navController.graph)

Additional configuration options for customizing the behavior of the Toolbar

setupWithNavController

fun Toolbar.setupWithNavController(
    navController: NavController,
    drawerLayout: DrawerLayout?
): Unit

Sets up a Toolbar for use with a NavController.

By calling this method, the title in the Toolbar will automatically be updated when the destination changes (assuming there is a valid label).

The start destination of your navigation graph is considered the only top level destination. On the start destination of your navigation graph, the Toolbar will show the drawer icon if the given drawerLayout is non null. On all other destinations, the Toolbar will show the Up button.

This method will call NavController.navigateUp when the navigation icon is clicked.

Parameters
navController: NavController

The NavController whose navigation actions will be reflected in the title of the Toolbar.

drawerLayout: DrawerLayout?

The DrawerLayout that should be toggled from the Navigation button