【问题标题】:TabActivity in library project, android.R.id.tabhost not found error库项目中的 TabActivity,android.R.id.tabhost not found 错误
【发布时间】:2011-06-22 17:30:23
【问题描述】:

我正在尝试创建模板/BaseActivity 类供其他开发人员使用,作为框架的一部分。

我用 TabActivity 扩展了我的类,我的 xml 看起来像这样/

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
        <View android:layout_width="fill_parent" android:layout_height="0dip"
            android:background="#000" />
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_marginLeft="0dip" android:layout_marginRight="0dip" />
        <View android:layout_width="fill_parent" android:layout_height="2dip"
            android:background="#696969" />
        <View android:layout_width="fill_parent" android:layout_height="1dip"
            android:background="#fff" />
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="fill_parent" />
    </LinearLayout>
</TabHost>

当我通过在其他项目中扩展来使用此活动时,我收到一条错误消息,指出无法获取 android.R.id.tabhost,这是必要的。

即使我在两种情况下都调用 getTabHost() 或 findViewById() 也会发生这种情况。

请注意:我在没有扩展 TabActivity 的情况下进行了尝试,以便在选项卡中使用视图。它工作正常。但我想使用活动作为我的标签内容。

我认为这是我们将其作为库项目并包含它时的问题。

如果您需要更多解释或知道一些解决方法,请告诉我,请提出建议。

【问题讨论】:

    标签: android android-layout android-tabhost android-library


    【解决方案1】:

    我解决了这个问题。 提供了一个库类,需要用户将当前活动实例传递给我的模板库。

    它调用将 Conetnt 设置为包含 android 选项卡的布局文件之一。 然后获取标签主机。

    如果有人想了解更多详情,请告诉我。 如果您正在开发一个为用户提供布局的框架。

    【讨论】:

    • 我遇到了同样的问题,我想查看更多详细信息或您如何解决它的代码示例。
    猜你喜欢
    • 2019-12-29
    • 2013-06-18
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 2017-10-24
    • 2013-02-20
    • 2018-01-16
    • 1970-01-01
    相关资源
    最近更新 更多