如何在Android中使操作栏标签中心对齐?

The*_*ram 2 android android-actionbar

我的操作栏标签左对齐,我想将其对齐居中.我怎样才能做到这一点?

Gol*_*k84 5

我能够通过自定义我的应用程序主题来居中对齐操作栏

在我的AndroidManifest.xml中,我添加了一个android:theme属性:

<application
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/CustomActionBarTheme">
  ...
Run Code Online (Sandbox Code Playgroud)

然后我在我的项目中添加了一个新的themes.xml文件,并添加了:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarTabBarStyle">@style/MyActionBarTabBar</item>
    </style>

    <style name="MyActionBarTabBar">
        <item name="android:gravity">center</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

标签现在应该居中对齐.

编辑:仅当您的操作栏显示在2行(纵向)时才有效