TabHost的坑

问题1.  运行Activity的时候出现Your content must have a TabHost whose id attribute is ‘android.R.id.tabhost’

问题2. 运行Activity的时候出现Your TabHost must have a TabWidget whose id attribute is ‘android.R.id.tabcontent’

这是由于 TabHost   id  的规范不同造成的。我们需要把id改成如下样式:

android:id="@android:id/tabhost"

android:id="@android:id/tabs"

android:id="@android:id/tabcontent"

而在获取使用findById时也有所不同:

tabhost = l.findViewById(android.R.id.tabhost);
tabwidget = l.findViewById(android.R.id.tabs);
tabcontent = l.findViewById(android.R.id.tabcontent);

 另外:一个工程只能有一个TabHost

 

猜你喜欢

转载自www.cnblogs.com/the-wang/p/9024737.html