带有导航选项卡的 ActionBar 会随着屏幕方向改变高度 [英] ActionBar with navigation tabs changes height with screen orientation

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

问题描述

我的目标是增加纵向模式的 ActionBar 高度.我目前设置

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

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

我在横向模式下获得了想要的效果,我将 ActionBar 的高度增加到 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.

注意我在代码中进行了以下调用.

Note I make the following calls in code.

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

我正在使用 Android 4.2 的 Nexus 7 进行开发.

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?

通过设置both Application 主题属性android:actionBarSize ActionBar.TabView 样式属性 android:minHeight(或 height)为 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" >

在 Activity 的 ActionBar 中添加一些选项卡:

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:

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

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