how to remove spacing between ActionBar icons

2020-04-21 02:16发布

问题:

Once again I'm fighting with ActionBar styles for SDK 14 and above. I'm trying to remove/reduce spacing between Tab icons since the default spacing does not fit well in my design. Currently my style looks like:

       <style name="sMain" parent="@android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/mTabAreaBackground</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item>
</style>

<style name="mTabAreaBackground" parent="@android:style/Widget.Holo.ActionBar.Solid">
    <item name="android:backgroundStacked">#2b2f33</item>
</style>

<style name="ActionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
    <item name="android:background">@android:color/transparent</item>
    <!-- below attributes have no effect -->
    <item name="android:width">0dp</item>
    <item name="android:height">0dp</item>
</style>

I "removed" the active Tab indicator by making it transparent since my Tab icons already have one. I assumed that the spacing between Tab icons was somehow related to the Tab indicator, which was still there though I made it transparent. Therefore I tried to apply a width and height of 0 in the same style (inherited from style/Widget.Holo.ActionBar.TabView). I don't know if my assumption was incorrect or I'm doing something wrong, I also could not find any documentation/examples related to adjusting spacing between Tab icons.

Any suggestions are appreciated.

回答1:

AFAIK, the spacing is because of the padding on the TabView. You should changing the padding on the TabView something like below.

<style name="ActionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
    <item name="android:background">@android:color/transparent</item>

    <item name="android:paddingLeft">2dp</item>
    <item name="android:paddingRight">2dp</item>
</style>

The default padding on the TabView seems to be 16dp.