Actionbar tabs don't fill the tabbar

2019-02-16 19:11发布

After hours of trying I finally found a method to separate the actionbar tabbar from the actionbar manualy. actionbar convert tabs to list navigation if there is no room But now there is one problem left. The tabs don't fill the tabbar. enter image description here

EDIT The tabs are added to the actionbar by: ActionBar.Tab relatieTab = actionBar.newTab().setText("Relaties"); actionBar.addTab(relatieTab);

3条回答
Deceive 欺骗
2楼-- · 2019-02-16 19:16

I just solved this problem today.
They key was using <item name="android:padding">0dp</item> like so...

<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar">
</style>

<style name="LoginActionBar"
    parent="@style/MyActionBar">
    <item name="android:actionBarTabStyle">@style/LoginActionBarTabs</item>
</style>

<style name="LoginActionBarTabs"
    parent="@android:style/Widget.Holo.ActionBar.TabView">
    <item name="android:padding">0dp</item>
</style>

You don't need that many styles, but I didn't want to take any chunks out, which may have lead to confusion.

I also see that you already worked around this, but I figured I'd add my answer for the next person to come looking for this.

查看更多
看我几分像从前
3楼-- · 2019-02-16 19:37

Use the following to customize the tabs in action bar:

<style name="MyAppActionBarTabStyle" parent="@android:style/Widget.ActionBar.TabView">
    <item name="android:background">@drawable/actionbar_tabindicator</item>
    <item name="android:minWidth">40dip</item>
    <item name="android:maxWidth">40dip</item>
    <item name="android:layout_width">0dip</item>
    <item name="android:layout_weight">1</item>
</style>

Make sure that the activity where you are setting these navigation tabs has the following in its @android:theme

<style name="MyAppTheme" parent="android:style/Theme.Holo.Light">
    <item name="android:actionBarTabStyle">@style/MyAppActionBarTabStyle</item>
</style>

I still could not figure how how to detect whether the tabbar is separate i.e. below main action bar or merged (when in landscape OR larger screens even in portrait)

Another interesting thing to know is how to prevent tab bar from collapsing to a spinner when space is not enough.

As and when I find out answers to my questions above, will update the post. Until then hope the styles help few other ppl

查看更多
对你真心纯属浪费
4楼-- · 2019-02-16 19:39

Try to switch the parent. If that doesn't work try visiting this post: Stacked ActionBar tab bar not filling parent

Good luck :)

查看更多
登录 后发表回答