我正在尝试从中添加文本TabView
但TextView
得到java.lang.IllegalStateException
活动代码:
public class Testimonial extends TabActivity {
private TabHost tabHost;
TextView video = null;
TextView text = null;
private void setupTabHost() {
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testimonial);
setupTabHost();
View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.testimonial_tab_row, null);
video = (TextView)view.findViewById(R.id.tabVideo);
text = (TextView)view.findViewById(R.id.tabText);
tabHost = getTabHost();
TabSpec videoSpec = tabHost.newTabSpec("Video");
videoSpec.setIndicator(video);
Intent videoIntent = new Intent(this,TestimonialVideo.class);
videoSpec.setContent(videoIntent);
TabSpec textSpec = tabHost.newTabSpec("Text");
textSpec.setIndicator(text);
Intent textIntent = new Intent(this, TestimonialText.class);
textSpec.setContent(textIntent);
tabHost.addTab(videoSpec);
tabHost.addTab(textSpec);
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tabdrawable);
}
tabHost.getTabWidget().setDividerDrawable(R.drawable.footer_saprater);
}
}
这是我的 testimonial.xml 代码
<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">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="@android:id/tabs"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/tabdrawable"
android:gravity="center_vertical|center_horizontal" />
</RelativeLayout>
</TabHost>
这是 testimonial_tab_row.xml 代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:gravity="center"
android:orientation="vertical">
<TextView android:id="@+id/tabVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video"
android:gravity="center"
android:textSize="22sp"
android:textColor="#fff" />
<TextView android:id="@+id/tabText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:gravity="center"
android:textSize="22sp"
android:textColor="#fff" />
</LinearLayout>