0
我目前已经开始为HoneyComb平板电脑组合应用程序。我已经使用ActionBar.Tab在ActionBar和Fragment上为每个Tab实现三个选项卡。三个标签名称关于,图库,设置。在设置ActionBar.Tab中,我想要TabHost。 这意味着如何在片段内使用TabHost。预先感谢您的想法!HoHenComb中的TabHost内部片段
我目前已经开始为HoneyComb平板电脑组合应用程序。我已经使用ActionBar.Tab在ActionBar和Fragment上为每个Tab实现三个选项卡。三个标签名称关于,图库,设置。在设置ActionBar.Tab中,我想要TabHost。 这意味着如何在片段内使用TabHost。预先感谢您的想法!HoHenComb中的TabHost内部片段
有像tabhost布局(假设你定义了这个my_fragment_tabhost):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:visibility="gone"
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"/>
</LinearLayout>
</TabHost>
</LinearLayout>
在你的片段,有一个TabHost成员变量,并把它在onCreateView,如:
private TabHost mTabHost;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_fragment_tabhost, container, false);
mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
mTabHost.setup();//very important to call this
TabHost.TabSpec tab = mTabHost.newTabSpec("my tab content");
tab.setIndicator("my tab content")
//... add your content by one of the tab.setContent() methods
mTabHost.addTab(tab);
return view;
}
你用这个mTabHost.setup()保存了我的屁股;谢谢。 – 2013-08-04 22:38:27