# MaterialToolbar

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/appbar/MaterialToolbar.java)

*** ** * ** ***


```
public class MaterialToolbar
```

<br />

*** ** * ** ***

`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 `https://developer.android.com/reference/com/google/android/material/appbar/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 `https://developer.android.com/reference/com/google/android/material/appbar/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

| ### Public fields |
|---|---|
| `ScaleType` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#logoScaleType()` |
| `https://developer.android.com/reference/java/lang/Integer` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#navigationIconTint()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#MaterialToolbar(Context)(Context context)` |
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#MaterialToolbar(Context,AttributeSet)(Context context, AttributeSet attrs)` |
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#MaterialToolbar(Context,AttributeSet,int)(Context context, AttributeSet attrs, int defStyleAttr)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#clearNavigationIconTint()()` Clears the tint list of the toolbar's navigation icon. |
| `ScaleType` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#getLogoScaleType()()` Returns scale type of logo's ImageView |
| `https://developer.android.com/reference/java/lang/Integer` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#getNavigationIconTint()()` Gets the tint color of the toolbar's navigation icon, or null if no tint color has been set. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#isLogoAdjustViewBounds()()` Returns logo's ImageView adjustViewBounds |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#isSubtitleCentered()()` Returns whether the subtitle text corresponding to the setSubtitle method should be centered horizontally within the toolbar. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#isTitleCentered()()` Returns whether the title text corresponding to the setTitle method should be centered horizontally within the toolbar. |
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setElevation(float)(float elevation)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setLogoAdjustViewBounds(boolean)(boolean logoAdjustViewBounds)` Sets ImageView.adjustViewBounds for logo's ImageView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setLogoScaleType(ImageView.ScaleType)(ScaleType logoScaleType)` Sets ImageView.ScaleType for logo's ImageView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setNavigationIcon(Drawable)(Drawable drawable)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setNavigationIconTint(int)(int navigationIconTint)` Sets the color of the toolbar's navigation icon. |
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setSubtitleCentered(boolean)(boolean subtitleCentered)` Sets whether the subtitle text corresponding to the setSubtitle method should be centered horizontally within the toolbar. |
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setTitleCentered(boolean)(boolean titleCentered)` Sets whether the title text corresponding to the setTitle method should be centered horizontally within the toolbar. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#onAttachedToWindow()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#onLayout(boolean,int,int,int,int)(boolean changed, int left, int top, int right, int bottom)` |

## Public fields

### logoScaleType

```
public ScaleType logoScaleType
```

### navigationIconTint

```
public Integer navigationIconTint
```

## Public constructors

### MaterialToolbar

```
public MaterialToolbar(Context context)
```

### MaterialToolbar

```
public MaterialToolbar(Context context, AttributeSet attrs)
```

### MaterialToolbar

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

## Public methods

### clearNavigationIconTint

```
public void clearNavigationIconTint()
```

Clears the tint list of the toolbar's navigation icon. E.g., if the navigation icon is an XML based vector drawable, calling this method will clear the `android:tint`.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setNavigationIconTint(int)` |   |

### getLogoScaleType

```
public ScaleType getLogoScaleType()
```

Returns scale type of logo's ImageView

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setLogoScaleType(ImageView.ScaleType)` | Default - null |

### getNavigationIconTint

```
public Integer getNavigationIconTint()
```

Gets the tint color of the toolbar's navigation icon, or null if no tint color has been set.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setNavigationIconTint(int)` |   |

### isLogoAdjustViewBounds

```
public boolean isLogoAdjustViewBounds()
```

Returns logo's ImageView adjustViewBounds

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setLogoAdjustViewBounds(boolean)` | Default - false |

### isSubtitleCentered

```
public boolean isSubtitleCentered()
```

Returns whether the subtitle text corresponding to the setSubtitle method should be centered horizontally within the toolbar.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setSubtitleCentered(boolean)` |   |

### isTitleCentered

```
public boolean isTitleCentered()
```

Returns whether the title text corresponding to the setTitle method should be centered horizontally within the toolbar.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setTitleCentered(boolean)` |   |

### setElevation

```
public void setElevation(float elevation)
```

### setLogoAdjustViewBounds

```
public void setLogoAdjustViewBounds(boolean logoAdjustViewBounds)
```

Sets ImageView.adjustViewBounds for logo's ImageView.

### setLogoScaleType

```
public void setLogoScaleType(ScaleType logoScaleType)
```

Sets ImageView.ScaleType for logo's ImageView.

### setNavigationIcon

```
public void setNavigationIcon(Drawable drawable)
```

### setNavigationIconTint

```
public void setNavigationIconTint(int navigationIconTint)
```

Sets the color of the toolbar's navigation icon.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/appbar/MaterialToolbar#setNavigationIcon(Drawable)` |   |

### setSubtitleCentered

```
public void setSubtitleCentered(boolean subtitleCentered)
```

Sets whether the subtitle text corresponding to the setSubtitle method should be centered horizontally within the toolbar.

Note: it is not recommended to use centered titles in conjunction with a nested custom view, as there may be positioning and overlap issues.

### setTitleCentered

```
public void setTitleCentered(boolean titleCentered)
```

Sets whether the title text corresponding to the setTitle method should be centered horizontally within the toolbar.

Note: it is not recommended to use centered titles in conjunction with a nested custom view, as there may be positioning and overlap issues.

## Protected methods

### onAttachedToWindow

```
protected void onAttachedToWindow()
```

### onLayout

```
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
```