question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Toolbar] How to center title of MaterialToolbar?

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

56reactions
dsn5ftcommented, Mar 15, 2021

Hi @luisventura, we recently added support for centered titles to MaterialToolbar via the new app:titleCentered and app: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.

2reactions
lencetanaskoskacommented, Jan 29, 2021

Can we expect that MaterialToolbar’s title alignment will be added in a next version?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found