TabHost requires a TabWidget with id "android:id/tabs" 报错解决办法
来源:互联网 发布:知乎关键指标kpi 编辑:程序博客网 时间:2024/06/06 00:39
最近使用了Android的tabHost控件,但是从网上拷贝代码的时候发现报错了。
报错信息是上面那个。
如题很简单,缺少了一个Tabweidge。
使用tabHost控件的时候要注意两点,第一,布局文件中的TabWidget的id必须定义为:android:id="@android:id/tabs",第二,FrameLayout的id必须定义为:android:id="@android:id/tabcontent" 其它控件没有限制,否则报错。
附上基本代码片段:
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/TabHost01" android:layout_width="fill_parent"android:layout_height="fill_parent"><LinearLayout android:layout_width="fill_parent"android:orientation="vertical" android:layout_height="fill_parent"><TabWidget android:id="@android:id/tabs"android:layout_width="fill_parent"android:layout_height="wrap_content" /><FrameLayout android:id="@android:id/tabcontent"android:layout_width="fill_parent"android:layout_height="fill_parent"><LinearLayout android:id="@+id/LinearLayout1"android:layout_width="fill_parent"android:layout_height="wrap_content"><TextView android:text="one"android:id="@+id/TextView01" android:layout_width="wrap_content"android:layout_height="wrap_content"></TextView></LinearLayout><LinearLayout android:id="@+id/LinearLayout2"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView android:text="two"android:id="@+id/TextView02" android:layout_width="fill_parent"android:layout_height="wrap_content"></TextView></LinearLayout><LinearLayout android:id="@+id/LinearLayout3"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView android:text="three"android:id="@+id/TextView03" android:layout_width="fill_parent"android:layout_height="wrap_content"></TextView></LinearLayout></FrameLayout></LinearLayout></TabHost>
其中最重要的是:
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/TabHost01" android:layout_width="fill_parent"android:layout_height="fill_parent"><LinearLayout android:layout_width="fill_parent"android:orientation="vertical" android:layout_height="fill_parent"><TabWidget android:id="@android:id/tabs"android:layout_width="fill_parent"android:layout_height="wrap_content" /><FrameLayout android:id="@android:id/tabcontent"android:layout_width="fill_parent"android:layout_height="fill_parent"><span style="white-space:pre"></span><!--插入内容--></FrameLayout></LinearLayout></TabHost>
这部分代码基本不要改,因为最重要的两个要求都在里面,然后只需要在插入内容里面插入LinearLayout就可以了。
别忘了最重要一点,每个LinearLayout都要一个专属的id,不可以空着不写,否则也会报错的
1 0
- TabHost requires a TabWidget with id "android:id/tabs" 报错解决办法
- 解决:[Android UI界面] 创建TabHost XML图形视图一直出错看不到内容?TabHost requires a TabWidget with id "android:id/tabs".
- 5 Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
- [BUG]Your TabHost must have a TabWidget whose id attribute is ‘android.R.id.tabcontent’
- 5 Your TabHost must have a TabWidget whose id attribute is ‘android.R.id.tabcontent’
- [ERROR]Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabcontent'
- TabHost报id错
- 搭建elsticsearch集群 报错with the same id but is a different node instance解决办法
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 问题,写了id语句仍出错的解决办法
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- 错误处理:your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- 错误处理:your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- 报错:ArrayAdapter requires the resource ID to be a TextView
- Java内存溢出的详细解决方案
- equal与equalsIgnoreCase的区别
- 网络编程学习(六)
- 简单计算器
- GetSaveFileName弹出文件选择框居中显示
- TabHost requires a TabWidget with id "android:id/tabs" 报错解决办法
- 在学校里面,曾经过做过的学生管理系统
- HDU 2082-找单词(母函数)
- PHP Fatal error: Class 'DOMDocument'未安装php-xml模块
- C++如何在派生类成员函数内调用基类的成员函数(包括构造函数)
- C++内存对齐
- 手游接入Facebook功能
- 润乾数据源连接报错
- selenium+testN数据驱动