部分代码如下
Activity中代码:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main_tabs);
this.myTabHost = this.getTabHost();
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
String title = bundle.getString("courseName");
TextView tvTitle = (TextView)findViewById(R.id.title_tab);
tvTitle.setText(title);
//this.myTabHost = (TabHost) super.findViewById(R.id.tabhost);
//this.myTabHost.setup(); //建立TabHost对象
intent = new Intent(TabClassActivity.this,CourseInfoActivity.class);
intent.putExtras(bundle);
TabSpec myTab1 = this.myTabHost.newTabSpec("courseInfo")
.setIndicator(getResources().getString(this.strRes[0]))
.setContent(intent);
myTabHost.addTab(myTab1);
intent = new Intent(TabClassActivity.this,RelativeCoursesActivity.class);
intent.putExtras(bundle);
TabSpec myTab2 = this.myTabHost.newTabSpec("relativeCourses")
.setIndicator(getResources().getString(this.strRes[1]))
.setContent(intent);
myTabHost.addTab(myTab2);
intent = new Intent(TabClassActivity.this,RelativeBooksActivity.class);
intent.putExtras(bundle);
TabSpec myTab3 = this.myTabHost.newTabSpec("relativeBooks")
.setIndicator(getResources().getString(this.strRes[2]))
.setContent(intent);
myTabHost.addTab(myTab3);
}
XML布局文件中代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/title_tab"
android:layout_width="match_parent"
android:layout_height="50sp"
android:background="@color/dark_gray"
android:textSize="25sp"
android:gravity="center"
android:textColor="@color/white"/>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:paddingBottom="60sp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RadioGroup
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<RadioButton
android:id="@+id/radio_bn0"
android:text="@string/courseInfo"/>
<RadioButton
android:id="@+id/radio_bn1"
android:text="@string/relativeCourses"/>
<RadioButton
android:id="@+id/radio_bn2"
android:text="@string/relativeBooks"/>
</RadioGroup>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</TabHost>
</LinearLayout>
开始好好的。好像是我在清单文件中设置了android:theme="@android:style/Theme.Light.NoTitleBar"就成这样了,为什么?
大神们求救啊。小弟初学Android。灰常感谢啦!