我按照網上的教程中找到,但似乎不工作...Tabhost沒有顯示標籤
我得到的選項卡1總是打開的,這是好的,但我沒有看到選項卡菜單了。 ..
這裏是我的代碼:
Main2Activity:
public class Main2Activity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
// create the TabHost that will contain the Tabs
TabHost tabs=(TabHost)findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("Analog Clock");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("DigitalClock");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag3");
spec.setContent(R.id.tab3);
spec.setIndicator("Button");
tabs.addTab(spec);
}
Content_main2.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
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">
<AnalogClock android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<DigitalClock android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<Button android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Do Nothing"/>
</FrameLayout>
</LinearLayout>
</TabHost>
This is how it looks when i run it
http://stackoverflow.com/questions/11918488/android-how-do-you-set-up-the-tabhost –