android:dividerPadding has no effect

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

This theme works fine, referencing three custom styles for the 3 parts of the ActionBar's tabs.

But the "dividerPadding" has no effect on any of them - running on API 17 devices.

 <style name="Theme.AppEmptyTitleBar" parent="android:style/Theme.Holo">         <item name="android:actionBarStyle">@style/AB</item>         <item name="android:actionBarTabStyle">@style/ABT</item>         <item name="android:actionBarTabBarStyle">@style/ABTB</item>     </style>  <style name="AB" parent="android:style/Widget.Holo.ActionBar">     <item name="android:dividerPadding">20dip</item> </style> <style name="ABT" parent="android:style/Widget.Holo.Light.ActionBar.TabView">     <item name="android:dividerPadding">20dip</item> </style> <style name="ABTB" parent="android:style/Widget.Holo.ActionBar.TabBar">     <item name="android:dividerPadding">20dip</item> </style> 

回答1:

First of all, the dividerPadding attribute is (as far as I know) only applicable to the *ActionBar.TabBar style.

I've tested your style using a very basic application making use of the native ActionBar and a device providing API 17. I've set the dividerPadding attribute to different values and left the rest of the attributes with default values. Here are the results:

  • dividerPadding="0dip":

  • dividerPadding="15dip":

  • dividerPadding="20dip":

As you can see, divider is gone on the last image. So my first advice would be to check if you see it at all. Other than that, the dividerPadding seems to be working as expected.

My second advice comes from the way Android platform handles style resources placed in different values-* directories. My hunch is that you might be making use of your action bar styles in the default values directory. If you then happen to provide an override of these styles in a values-* directory which is compatible (e.g. values-vX where X <= 17), the styles from values will be ignored. As an example, consider that you've placed these sample styles in the values/styles.xml file:

<resources xmlns:android="http://schemas.android.com/apk/res/android">     <style name="AppTheme" parent="@android:style/Theme.Holo">         <item name="android:actionBarTabBarStyle">@style/ABTB</item>     </style>      <style name="ABTB" parent="@android:style/Widget.Holo.ActionBar.TabBar">         <item name="android:dividerPadding">0dip</item>     </style> </resources> 

If you then place this style definition in values-v17/styles.xml:

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

it will override the AppTheme style, effectively "resetting" (technically: ignoring) the whole actionBarTabBarStyle style (including the dividerPadding attribute value). In effect, you won't see any changes made to the ABTB style.

Edit

Yup, I assumed you know that, sorry :( The dividerPadding value applies only to:

  • Top and bottom of divider when the TabWidget (it's the container of tab labels) draws tabs horizontally.
  • Left and right sides of divider when the TabWidget draws tabs vertically.

Which is exactly what you see in the screenshots. As far as I know, you have to set divider to a drawable which will force additional padding. I believe the layer drawable will be great for that purpose because you can set padding explicitly for every layer.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!