[Toolbar] How to center title of MaterialToolbar?
See original GitHub issueI am trying to center the title of the MaterialToolbar, tried to add android: gravity but it doesn’t work. There is no info in the documentation on how to center it
<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">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:liftOnScroll="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:focusable="false"
app:liftOnScrollTargetViewId="@id/brokers_recycler_view"
app:expanded="false">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/material_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center_horizontal"
android:elevation="0dp"
app:layout_scrollFlags="scroll|enterAlways|snap|exitUntilCollapsed"
app:contentInsetLeft="@dimen/margin_16"
app:contentInsetStart="@dimen/margin_16"
app:menu="@menu/toolbar_menu"
app:titleTextAppearance="@style/TextAppearance.App.CollapsingToolbar.Collapsed"/>
</com.google.android.material.appbar.AppBarLayout>
....
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Change the title of MaterialToolbar into center - Stack Overflow
Starting from com.google.android.material:material:1.4.0 you can use app:titleCentered="true" to center the title.
Read more >MaterialToolbar - Android Developers
MaterialToolbar is a Toolbar that implements certain Material features, such as elevation overlays for Dark Themes and centered titles.
Read more >Make Android Toolbar text center aligned - Code2care
This tutorial helps you align the Android Toolbar text in the center. ... By default the Title text in the Android Toolbar is...
Read more >Android Tutorial 12: Create Custom Toolbar and Center Title ...
In this chapter, we will create a custom Toolbar and center the title using a custom textview. For this, we are adding ...
Read more >The Joy of Custom Views: How to make a centered title ...
Centering a title in a toolbar sounds like a stupidly simple thing to do, but from my experience it's one of those “stupidly...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @luisventura, we recently added support for centered titles to
MaterialToolbar
via the newapp:titleCentered
andapp:subtitleCentered
attributes, in the commit linked above (cbf528e3a6deaa2bc39d0836b3a850b27c2ada49). That’s why this issue was closed.It will be included in our next alpha release, but in the meantime you can try it out with our snapshot release.
Can we expect that MaterialToolbar’s title alignment will be added in a next version?