試試我的代碼。您將能夠使用操作欄和tabhost分段。
1) XML file for Activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
2) Java code for Activity:
public class CarsActivity extends FragmentActivity implements YourFragment.OnFragmentInteractionListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
_mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
_mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
//add your fragments here:
_mTabHost.addTab(_mTabHost.newTabSpec("*UNIQE IDENTIFIER OF YOUR FRAGMENT").setIndicator("*DISPLAY NAME ON TAB*"),
YourFragment.class, null);
}
});
@Override
public void onFragmentInteraction(Uri uri)
{}
}
'TabActivity'已被棄用**超過四年**。請使用現代技術製表符,例如帶有標籤指示符的'ViewPager'。 – CommonsWare