android – 在没有任何代码的情况下在xml文件中定义Tabhost / TabWidget内容 – 可能吗?

是否可以仅在布局xml文件中定义选项卡布局?每次我找到tabhost教程时,它只适用于一些额外的java代码.

这是我的test.xml,它不显示任何标签

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/linearLayout">
    <TextView android:text="@string/app_name" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
    <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">
        <TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs">
        </TabWidget>
        <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1">
                <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TAB 1"/>
            </LinearLayout>   
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2">
                <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TAB 2"/>
            </LinearLayout>
        </FrameLayout>
    </TabHost>
</LinearLayout>

解决方法:

它是不可能的,因为TabSpec是持有者类,代表TabHost中的每个选项卡.
并且没有指定要在xml布局中放置的TabSpec xml等效标记.

即使通过代码,对于TabSpec,也必须指定指标和内​​容.否则它会抛出

IllegalArgumentException: you must specify a way to create the tab content

要么

IllegalArgumentException: you must specify a way to create the tab indicator.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...