您的位置:首页 > 移动开发 > Android开发

Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决

2013-04-24 15:18 381 查看
问题1. 运行Activity的时候出现Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

添加Layout的时候,xml跟元素选择TabHost, 但是ADT没有添加id属性, 运行的时候,会提示Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'错误, 需要添加android:id="@android:id/tabhost", 这样就可以了。

问题2. 运行Activity的时候出现Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabcontent'
解决方法: 修改FrameLayout添加id属性, ADT自动生成的xml文件中Id是android:id="@+id/FrameLayout01 ", 需要修改成下面的格式android:id="@android:id/tabcontent ",这个估计会困扰一大批初学者,谁会想到会修改这个地方,看到错误很容易修改成tabcontent,但是前缀不容易想到。 而且在ADT可视化编辑这个文件的时候, 界面上显示NullPointerException,这个是ADT的一个BUG。

xml文件代码:

<?xml version="1.0" encoding="utf-8"?>
<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" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<!-- 实现Tab标签的居底主要是通过设置属性 android:layout_weight="1" -->
<!-- 还要注意FrameLayout标签的位置,要写在TabWidget标签的前面 -->

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />

<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</LinearLayout>

</TabHost>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android tabhost
相关文章推荐