I try to center the text in my toolbar. I use AppBarLayout
and MaterialToolbar
, as suggested in Material Design.
I tried everything I found on StackOverflow to center the title, but nothing seemed to work.
This is my toolbar:
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/topAppBar"
style="@style/CenteredToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
</com.google.android.material.appbar.AppBarLayout>
And CenteredToolbar
is my custom style where I tried to center the title:
<style name="CenteredToolbar" parent="Widget.MaterialComponents.Toolbar.Primary">
<item name="android:gravity">center_horizontal</item>
</style>
This doesn't work, however.
Any suggestions on what I can do to center the title?