【问题标题】:Android ICS displaying tabactivity tabs wrongAndroid ICS 显示 tabactivity 选项卡错误
【发布时间】:2019-08-16 09:26:59
【问题描述】:

我有一个使用 TabActivity 的应用程序,但它在 ICS 上呈现不正确。对 ActionBar 或 Fragments 作为解决方案并不真正感兴趣,因为这些选项卡仍然适用于我和其他应用程序。

这是在所有其他版本的 android 上的外观(所需外观)

这是它在 ICS 上的样子,不正确。

这是我的 tabactivity 选项卡代码,需要更改什么?

    intent = new Intent().setClass(this, HomeMenuGroup.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    spec = tabHost.newTabSpec("homeMenuGroup").setIndicator(li.inflate(R.layout.main_tabs_home, tabHost.getTabContentView(), false))
            .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, BuyTicketsGroup.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    spec = tabHost.newTabSpec("buyTicketsGroup").setIndicator(li.inflate(R.layout.main_tabs_buy, tabHost.getTabContentView(), false))
            .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, UseTicketsGroup.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    spec = tabHost.newTabSpec("useTicketsGroup").setIndicator(li.inflate(R.layout.main_tabs_use, tabHost.getTabContentView(), false))
            .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, MyAccountGroup.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    spec = tabHost.newTabSpec("myAccountGroup").setIndicator(li.inflate(R.layout.main_tabs_account, tabHost.getTabContentView(), false))
            .setContent(intent);
    tabHost.addTab(spec);

这是我的标签按钮布局之一 xml R.layout.main_tabs_account

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:background="@drawable/switcher_account"
      android:layout_width="80dip"
      android:layout_height="60dip"/>
 </LinearLayout>

【问题讨论】:

    标签: android tabs android-4.0-ice-cream-sandwich tabactivity


    【解决方案1】:

    很难给你一个明确的答案。例如,您引用的 R.layout.main_tabs_account 布局不包含屏幕截图显示的 ImageView,这表明您的问题中有些内容不同步。

    话虽如此,这就是我要尝试的:

    • 将尺寸从 TextView 移动到 LinearLayout。您的文字不应该是 80x60 dip;你的标签大概是。

    • 考虑发布包含您的TabHostTabWidget 的布局,因为这可能会提供更多线索。

    • 看看this project,我在其中使用自定义选项卡,看看我处理它的方法是否对您有帮助。该项目在 Android 4.0 上运行良好。

    【讨论】:

    • 感谢您指出有关 main_tabs_content 的信息。它是一个带有背景可绘制状态的文本视图。我会看看删除线性布局并将 textview 更改为 imageview 会发生什么
    • 成功了。感谢您的回复,我只是阅读了您的建议以及我想象的可能是错误的。在其他 2.x 设备上测试只是为了确保我保持兼容性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多