MaterialToolbar

public class MaterialToolbar
extends Toolbar

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ androidx.appcompat.widget.Toolbar
         ↳ com.google.android.material.appbar.MaterialToolbar


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

Regarding the Dark Theme elevation overlays, it's important to note that the Material AppBarLayout 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"/>
 

Summary

Inherited constants

Inherited fields

Public constructors

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

Public methods

void setElevation(float elevation)
void setNavigationIcon(Drawable drawable)
void setNavigationIconTint(int navigationIconTint)

Sets the color of the toolbar's navigation icon.

Protected methods

void onAttachedToWindow()

Inherited methods

Public constructors

MaterialToolbar

public MaterialToolbar (Context context)

Parameters
context Context

MaterialToolbar

public MaterialToolbar (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

MaterialToolbar

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

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

setElevation

public void setElevation (float elevation)

Parameters
elevation float

setNavigationIcon

public void setNavigationIcon (Drawable drawable)

Parameters
drawable Drawable

setNavigationIconTint

public void setNavigationIconTint (int navigationIconTint)

Sets the color of the toolbar's navigation icon.

Parameters
navigationIconTint int

Protected methods

onAttachedToWindow

protected void onAttachedToWindow ()