Tabhost内的Tabhost抛出运行时错误(您的内容必须具有id属性为';android.R.id.Tabhost';)
当尝试在tabhost中嵌入tabhost时,我会遇到此错误Tabhost内的Tabhost抛出运行时错误(您的内容必须具有id属性为';android.R.id.Tabhost';),android,runtime,android-tabhost,Android,Runtime,Android Tabhost,当尝试在tabhost中嵌入tabhost时,我会遇到此错误 ava.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tabdemo/com.example.tabdemo.Tab3Activity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.t
ava.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tabdemo/com.example.tabdemo.Tab3Activity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
来自tab3.java的我的tabhost代码(我是否希望tabhost加入)
这是我当前的tab3.xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="16dp"
android:background="#00547d"
>
<TextView
android:id="@+id/Job_Number_Label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Job Number"
android:textSize="20dp"
android:textColor="#ffffff" />
</LinearLayout>
</ScrollView>
我认为问题在于页面。只需更改布局文件,并根据您的要求使用此布局即可实现
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</LinearLayout>
错误原因是文本视图如果要在选项卡中使用带有文本视图的图标,请为文本视图创建另一个自定义布局,并在活动中使用此布局了解更多详细信息
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</LinearLayout>