Tabhost不工作

时间:2016-03-25 09:56:25

标签: android android-tabhost

  

我正在尝试在我的活动中添加标签但是当我运行应用程序崩溃时说"不幸的是app停止"。请帮助我,因为我是android新手...谢谢...   这是我的Java代码......

tabHost = (TabHost)findViewById(android.R.id.tabhost);


    // Tab for Upcoming Matches
    TabHost.TabSpec photospec = tabHost.newTabSpec("Upcoming Matches");
    // setting Title and Icon for the Tab
    //photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
    Intent photosIntent = new Intent(this, Upcoming_matches.class);
    photospec.setContent(photosIntent);

    // Tab for Recent Matches
    TabHost.TabSpec songspec = tabHost.newTabSpec("Recent Matches");
    //songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
    Intent songsIntent = new Intent(this, Recent_matches.class);
    songspec.setContent(songsIntent);

    // Tab for Fixtures
    TabHost.TabSpec videospec = tabHost.newTabSpec("Fixtures");
    //videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
    Intent videosIntent = new Intent(this, Fixtures.class);
    videospec.setContent(videosIntent);

    // Adding all TabSpec to TabHost
    tabHost.addTab(photospec); // Adding upcoming matches tab
    tabHost.addTab(songspec); // Adding recent matches tab
    tabHost.addTab(videospec); // Adding fixtures tab
  

这是我的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"
            android:layout_marginTop="215dp">
            <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="60dp" />
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"/>
            </LinearLayout>
        </TabHost>

0 个答案:

没有答案