动作条带导航选项卡更改高度与屏幕方向 [英] ActionBar with navigation tabs changes height with screen orientation

查看:136
本文介绍了动作条带导航选项卡更改高度与屏幕方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是增加动作条高度纵向模式。我当前设置

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

安卓actionBarSize

android:actionBarSize

在我的themes.xml。

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>

我得到在横向模式下,我已经增加了动作条高度80dp预期的效果。

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

不过,我去了旋转屏幕为纵向模式的高度变化,像这样。

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

请注意我作出code以下电话。

Note I make the following calls in code.

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

我开发的一台Nexus 7与Android 4.2。

I am developing on a Nexus 7 with android 4.2.

我如何得到相同的80dp高度在纵向模式下,我在横向模式?

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

推荐答案

您写的:

我如何得到相同的80dp高度在纵向模式下,我在横向模式?

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

通过设置双方应用程序主题属性安卓actionBarSize ActionBar.TabView style属性安卓了minHeight (或高度)以80畅游。

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

有一个基本的例子:

<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>

在清单设置主题:

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

这会产生在纵向模式下卡口与80浸高度:

This produces tabs with 80 dip height in portrait mode:

和80浸高度的标签在横向模式下:

and tabs with 80 dip height in landscape mode:

编辑:

有关本实施例中,SDK版本中的清单被设定为:

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

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

据OP,这个例子与这些SDK设置。但是,如果 targetSkdVersion ,而不是被设置为16或17,本例不工作。 OP已提起错误报告:

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:

这篇关于动作条带导航选项卡更改高度与屏幕方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆