I am using ActionBarSherlock and have an ActionBar with navigation tabs in it. I want the tabs to auto-size based on the size of the text in them, but there seems to be a style
Override this class in project ActionBarSherlock ./ActionbarSherlock/src/com/actionbarsherlock/internal/widget/ScrollingTabContainerView.java
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Re-measure if we went beyond our maximum size.
if (mParent.mMaxTabWidth > 0 && getMeasuredWidth() > mParent.mMaxTabWidth) {
//do nothing , override by me for ActionBarTabs not rezize never
}
}
Original code from
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Re-measure if we went beyond our maximum size.
if (mParent.mMaxTabWidth > 0 && getMeasuredWidth() > mParent.mMaxTabWidth) {
super.onMeasure(MeasureSpec.makeMeasureSpec(mParent.mMaxTabWidth, MeasureSpec.EXACTLY),
heightMeasureSpec);
}
}
When run , that code in android 2.3.3 works fine when my Tabs not broken line, but in android 4.4 not works.
Seems that you're just using the theme for the pre 4.0 android mode of ActionBarSherlock?
From http://actionbarsherlock.com/theming.html:
Mirrored Attributes
Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation. Since both theming APIs are exactly the same you need only reference your customizations twice rather than having to implement them twice.
The easiest way to convey exactly what this entails is with an example. The following is the full theme from the “Styled” example mentioned above:
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">@drawable/bg_striped</item>
<item name="android:background">@drawable/bg_striped</item>
<item name="backgroundSplit">@drawable/bg_striped_split</item>
<item name="android:backgroundSplit">@drawable/bg_striped_split</item>
</style>
From that screen shot it looks like you are testing on ICS which is good since you will be observing the behavior of the native action bar rather than think it is a bug with ActionBarSherlock.
Basically the action bar will attempt to expand tabs to take up an equal amount of space if there is enough room to do so in order to provide a cleaner look when there are only a few tabs.
By setting the actionBarTabTextStyle
padding to zero you are actually making the problem worse since now the text in the first tab has nothing around it to prevent it from touching the dividers and edge of screen. If you increase the padding (or return it to default) you should see one of two things:
I'm inclined to think that the former will happen due to the very thin widths of your second through fourth tab. Unfortunately this is just how the tab bar behaves and we need to just try an accomodate its behavior accordingly.
If possible, try to create tab labels that have a more unified width which will likely trigger the second state mentioned above. Keep testing with ICS so that you can ensure the behavior you're seeing is from the platform and then when running on pre-ICS you should get the same behavior from the library.