How to set height of actionbar tabs for android

2019-03-19 04:42发布

Basically, I want to change the height of the tabs in actionbars. This questions has been asked several times on stackoverflow, for example:

ActionBar tabs height

I have tried most of the solutions but nothing work, here is my code.

    <style name="CustomActionBarTheme" parent="@android:style/Theme.Holo">
    <item name="android:scrollHorizontally">false</item>
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">0dp</item>
    <item name="android:actionBarSize">80dp</item>
    <item name="actionBarSize">80dp</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item>
</style>

<style name="ActionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
    <item name="android:height">80dp</item>
</style>

Apparently, the code only change the actionbar height, not the tab bar height as I want. Here is the picture for reference:

enter image description here enter image description here

As you can see, the actionbar on the bottom is higher. But in actionbar mode, the tabs height remain the same.

Why is this happening? Did i miss something??? Thank you in advance :).

Solved, as mention in:

ActionBar with navigation tabs changes height with screen orientation

and

https://code.google.com/p/android/issues/detail?id=41792

Apparently this is a bug from android sdk ... Never though I would encounter a bug like this :(. Hope this help other people.

2条回答
Fickle 薄情
2楼-- · 2019-03-19 05:12

By setting both the Application theme attribute android:actionBarSize and the ActionBar.TabView style attribute android:minHeight (or height) to 80 dp. A basic example:

<style name="ThemeHoloWithActionBar" parent="android:Theme.Holo.Light">
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item>
    <item name="android:actionBarSize">80dp</item>
</style>

<style name="ActionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
    <item name="android:minHeight">80dp</item>
</style>

Set theme in Manifest:

   <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/ThemeHoloWithActionBar" >

Activity

        ActionBar actionbar = getActionBar();
        actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionbar.setDisplayShowTitleEnabled(false);
        actionbar.setDisplayShowHomeEnabled(false);
        ActionBar.Tab tabA = actionbar.newTab().setText("Tab A");
        ActionBar.Tab tabB = actionbar.newTab().setText("Tab B");
        ActionBar.Tab tabC = actionbar.newTab().setText("Tab C");
        tabA.setTabListener(new MyTabsListener());
        tabB.setTabListener(new MyTabsListener());
        tabC.setTabListener(new MyTabsListener());
        actionbar.addTab(tabA);
        actionbar.addTab(tabB);
        actionbar.addTab(tabC);
查看更多
beautiful°
3楼-- · 2019-03-19 05:20

From what I see in the documentation, it seems like it is not possible to change the tab height. But you can use a workaround - try using PagerSlidingTabStrip instead of ActionbarTabs. You can change the height in there easily.

查看更多
登录 后发表回答