支持工具栏title/menu垂直居中

Support Toolbar title/menu vertical centre

我是 android 开发的新手,我正在开发一个带有 ActionBar 和 Tabs 的应用程序。最近我切换到新的支持库 Toolbar 但工具栏 (ActionBar) 的标题不是垂直居中的,而操作按钮的位置是正确的。 Title image

栏中的第一个 MenuItem 出现同样的问题(向上移动了一点)。 Menu image

我的 activity 扩展了 AppCompatActivty,布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                 xmlns:app="http://schemas.android.com/apk/res-auto"
                                                 xmlns:tools="http://schemas.android.com/tools"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent"
                                                 android:orientation="vertical"
                                                 tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/action_bar_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            app:theme="@style/ActionBarTheme"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:tabGravity="fill"
            app:tabMaxWidth="0dp"
            app:tabMode="fixed"/>

        <com.myApp.app.views.widgets.ViewPager
            android:id="@+id/fragmentPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"/>
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

和样式:

 <style name="ActionBarTheme" parent="Widget.AppCompat.Toolbar">
        <item name="android:textColorPrimary">@color/colorPrimaryDark</item>
        <item name="colorControlNormal">@color/colorPrimaryDark</item>
        <item name="android:background">@color/colorPrimary</item>
  </style>

有人可以帮我解决这个问题吗?我已经搜索了解决方案,但一无所获。

P.S。它们被正确放置,因为我使用的是默认操作栏

你应该在这里使用 android:theme 而不是 app:theme:

android:theme="@style/ActionBarTheme"

您的风格应源自操作栏叠加层:

<style name="ActionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
...
</style>

考虑直接使用 ActionBar 主题来开始隔离问题。