自定义 ActionBar 标签支持的填充方式

5

我想去掉ActionBar选项卡之间的填充(空格)。

我正在使用Android Support Library V7(Appcompat)在Android 2.2 API 8作为minSDK和4.4 API 19作为maxSDK中使用Fragments和ActionBar。

我尝试过以下方法,但没有改变任何内容。

我的styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="@style/Widget.AppCompat.ActionBar.TabView">@style/TabBarStyle</item>
    </style>

   <style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView">
        <item name="android:paddingLeft">2dp</item>
        <item name="android:paddingRight">2dp</item>
    </style>
</resources>

AndroidManifest.xml 中的我的活动内容

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:uiOptions="splitActionBarWhenNarrow" >

请问有人能够向我展示如何正确地扩展和使用自定义主题吗?
1个回答

4

AndroidManifest.xml配置为使用自定义主题:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ....
    <application
        ...
        android:theme="@style/AppTheme"
        ...
    >
    ...
    </application>
    ....
</manifest>

res/values/styles.xml中定义您的自定义主题。

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Use a custom Application theme extending an existing AppCompat theme. -->
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    </style>

    <!-- customize parts of your theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- indicate that the actionBar uses a custom style and configure the link -->
        <item name="actionBarTabStyle">@style/TabBarStyle</item>
    </style>

    <!-- configure your real custom style for the tab bar-->
    <style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView">
        <item name="android:paddingLeft">5dp</item>
        <item name="android:paddingRight">5dp</item>
        <item name="android:minWidth">10dp</item>
        <item name="android:maxWidth">15dp</item>
    </style>

</resources>

以下内容应放置在res/values/styles-v11.xmlres/values/styles-v14.xml中。
<style name="AppTheme" parent="AppBaseTheme">
    <item name="actionBarTabStyle">@style/TabBarStyle</item>
</style>

<style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView">
    <item name="android:paddingLeft">5dp</item>
    <item name="android:paddingRight">5dp</item>
    <item name="android:minWidth">10dp</item>
    <item name="android:maxWidth">15dp</item>
</style>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接