user4351462
user4351462

Reputation: 181

Align the text in the toolbar with the icons

Here's how my toolbar currently looks. The text seems completely mislaid.

enter image description here

Here's the code:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:background="@color/blue_grey_900"
    android:gravity="center"
    android:minHeight="?android:attr/actionBarSize"
    app:popupTheme="@style/ToolbarPopup"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:elevation="5dp"/>

What's causing the misalignment?

Upvotes: 3

Views: 1147

Answers (2)

max59
max59

Reputation: 606

You can use a custom TextView in your XML like:

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/blue_grey_900"
android:gravity="center"
android:minHeight="?android:attr/actionBarSize"
app:popupTheme="@style/ToolbarPopup"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:elevation="5dp">

  <TextView
    android:id="@+id/toolbar_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Title"
    android:layout_gravity="center"/>

</android.support.v7.widget.Toolbar>

Then you can customize it or place the title anywhere you want.

Upvotes: 0

royB
royB

Reputation: 12977

change your code to android:layout_height="?attr/actionBarSize

Upvotes: 2

Related Questions