actionBarSize

http://stackoverflow.com/questions/13827762/actionbar-with-navigation-tabs-changes-height-with-screen-orientation



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?

share | improve this question
 
I've experienced the same issue, and I was wondering if you are also using this "reflection hack" to force embedded tabs in the action bar. –  mdelolmo  Mar 8 at 17:01

2 Answers

up vote 3 down vote accepted
+50

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 theActionBar.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 | improve this answer
 
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. –  ericharlow  Dec 20 '12 at 20:54
 
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. –  Gunnar Karlsson  Dec 21 '12 at 7:48
 
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 Dec 21 '12 at 17:44
 
For anyone interested in this issue please star it at code.google.com/p/android/issues/detail?id=41792 –  ericharlow  Dec 21 '12 at 18:46

use Fragments for making tabs ...... follow this link :http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/ ..... it will help you a lot

share | improve this answer
 
Fragments are irrelevant in setting the height of the actionBar. –  ericharlow  Dec 27 '12 at 16:37
以下代码,请帮我将Textview修改为一个imageview 。谢谢 。<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:didi="http://schemas.android.com/apk/res-auto" > <com.blog.demo10.NestedViewGroup android:id="@+id/dd_view_group" android:layout_width="match_parent" android:layout_height="match_parent" didi:header_id="@+id/view_bg" didi:target_id="@+id/target_layout" didi:inn_id="@+id/inner_rv" didi:header_init_top="0" didi:target_init_bottom="250"> <TextView android:id="@+id/view_bg" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:textColor="#f00" android:textSize="25sp" android:textAllCaps="false" android:text="@string/txt_nested_scroll_bg" /> <LinearLayout android:id="@+id/target_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="#fff"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/inner_rv" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> </com.blog.demo10.NestedViewGroup> <androidx.appcompat.widget.Toolbar android:id="@+id/my_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:elevation="4dp" android:theme="@style/ThemeOverlay.AppCompat.ActionBar" didi:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </RelativeLayout>
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值