MaterialToolbar

MaterialToolbar is a Toolbar that implements certain Material features, such as elevation overlays for Dark Themes and centered titles.

Regarding the Dark Theme elevation overlays, it's important to note that the Material component also provides elevation overlay support, and operates under the assumption that the child Toolbar does not have a background. While a MaterialToolbar with a transparent background can be used within an AppBarLayout, in terms of elevation overlays its main value comes into play with the standalone Toolbar case, when using the Widget.MaterialComponents.Toolbar.Surface style with elevation.

To get started with the MaterialToolbar component, use com.google.android.material.appbar.MaterialToolbar in your layout XML instead of androidx.appcompat.widget.Toolbar or Toolbar. E.g.,:

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

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)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
Clears the tint list of the toolbar's navigation icon.
Link copied to clipboard
open fun inflateMenu(i: Int)
Link copied to clipboard
Returns logo's ImageView adjustViewBounds
Link copied to clipboard
Returns whether the subtitle text corresponding to the setSubtitle method should be centered horizontally within the toolbar.
Link copied to clipboard
Returns whether the title text corresponding to the setTitle method should be centered horizontally within the toolbar.
Link copied to clipboard
Link copied to clipboard
open fun setLogoAdjustViewBounds(logoAdjustViewBounds: Boolean)
Sets ImageView.adjustViewBounds for logo's ImageView.
Link copied to clipboard
open fun setNavigationIcon(@Nullable drawable: Drawable)
Link copied to clipboard
open fun setNavigationIconTint(@ColorInt navigationIconTint: Int)
Sets the color of the toolbar's navigation icon.
Link copied to clipboard
open fun setSubtitleCentered(subtitleCentered: Boolean)
Sets whether the subtitle text corresponding to the setSubtitle method should be centered horizontally within the toolbar.
Link copied to clipboard
open fun setTitleCentered(titleCentered: Boolean)
Sets whether the title text corresponding to the setTitle method should be centered horizontally within the toolbar.