2

I'm trying to center the Toolbar text title and I can't. I've already tried to use a theme (didn't work) and Java code (as I'm working with API level 13 I can't use .setTextAligment), I've also tried getSupportActionBar().setDisplayOptions(toolbar.TEXT_ALIGNMENT_CENTER) that didn't work too. Can you please help me?

styles.xml

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    </style>
    <style name="AppTheme.Toolbar.Title" parent="Theme.AppCompat.NoActionBar">
        <!-- Set proper title size -->
        <item name="android:textSize">@dimen/abc_text_size_title_material_toolbar</item>
        <item name="android:gravity">center</item>
        <item name="android:layout_gravity">center</item>
    </style>
</resources>

layout.xml

<android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:background="@drawable/toolbar_main"
        style="@style/AppTheme.Toolbar.Title">    
    </android.support.v7.widget.Toolbar>

I've already tried the solution described here, but it didn't worked for me.

Community
  • 1
  • 1
porthfind
  • 1,581
  • 3
  • 17
  • 30

0 Answers0