ActionBar with navigation tabs changes height with screen orientation

15,350

You wrote:

How do I get the same 80dp height in portrait mode that I have in landscape mode?

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

A basic example:

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

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

Set theme in Manifest:

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

Add some tabs to the ActionBar in an Activity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    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);
}

This produces tabs with 80 dip height in portrait mode:

enter image description here

and tabs with 80 dip height in landscape mode:

enter image description here

EDIT:

For this example, SDK versions in the Manifest were set to:

android:minSdkVersion="12"
android:targetSdkVersion="15"

According to OP, the example works with these SDK settings. However, if targetSkdVersion is instead set to 16 or 17, the example doesn't work. OP has filed a bug report:

Share:
15,350
ericharlow
Author by

ericharlow

My passion is for mobile development. I am a problem solver with a keen ability to break complex problems down into manageable steps. For Fun: I enjoy the outdoors. hiking, backpacking, mountain biking, rock climbing, fly fishing.

Updated on July 20, 2022

Comments

  • ericharlow
    ericharlow almost 2 years

    My goal is to increase the ActionBar height for portrait mode. I currently set

    android:actionBarSize

    in my Themes.xml.

    <?xml version="1.0" encoding="utf-8"?>
    <resources xmlns:android="http://schemas.android.com/apk/res/android">
        <style name="DayTheme" parent="android:style/Theme.Holo.Light">
            <item name="android:actionBarSize">@dimen/actionBarHeight</item>
            <item name="android:actionBarTabTextStyle">@style/tab_indicator_text_dark</item>
        </style>
        <style name="NightTheme" parent="android:style/Theme.Holo">
            <item name="android:actionBarSize">@dimen/actionBarHeight</item>
            <item name="android:actionBarTabTextStyle">@style/tab_indicator_text_light</item>
        </style>
    </resources>
    

    I get the desired effect in landscape mode where I have increased the ActionBar height to 80dp.

    enter image description here

    However, went I rotate the screen into portrait mode the height changes like so.

    enter image description here

    Note I make the following calls in code.

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayShowTitleEnabled(false);
    bar.setDisplayShowHomeEnabled(false);
    

    I am developing on a Nexus 7 with android 4.2.

    How do I get the same 80dp height in portrait mode that I have in landscape mode?

  • ericharlow
    ericharlow over 11 years
    I tried your suggestion in a new sample project. I ran it on my nexus 7 and on the emulator. Neither of them produced the results like your picture of the height in portrait mode. In portrait mode the height is still less than the height in landscape mode.
  • onosendai
    onosendai over 11 years
    I've uploaded it as a project to github: github.com/GunnarKarlsson/TabHeightTest. Try if it produces the expected results on your nexus 7. My screen shots were from Galaxy S2 running 4.03.
  • ericharlow
    ericharlow over 11 years
    Thanks for the project it works! So the difference between your project and mine was in the AndroidManifest.xml. <uses-sdk android:minSdkVersion="12" android:targetSdkVersion="15" /> if you change the skd version to 16 or 17 it stops working. I am going to file a bug report for the android team.
  • ericharlow
    ericharlow over 11 years
    For anyone interested in this issue please star it at code.google.com/p/android/issues/detail?id=41792
  • Jonathan Ellis
    Jonathan Ellis over 10 years
    Not working for me at all (regardless of minSdkVersion or targetSdkVersion) on Android 4.3 on a Nexus 4. The tabs are just default height in portrait and the new size only takes place in landscape. Anyone with any suggestions? This issue is really frustrating!!