我的开发环境是带有 API19 SDK 的 Android Studio 0.8.9。
如果我将 FragmentTabHost 放在 FragmentActivity 中,它就可以工作。当我将 FragmentTabHost 放在 Fragment 中时,它会在渲染时出现“没有已知标签为空的标签”,并在 LayoutInflater 膨胀布局时出现运行时错误。
感谢 user3216049 的回答,这是一个很好的解决方法。抱歉,我是新手,无法投票。:(
但是它在我的测试选项卡片段中没有显示任何内容。我做了一个小修改。
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
<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"/>
<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:orientation="horizontal" />
</LinearLayout>
- fragment_section_dummy.xml
 
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="24sp"
android:padding="32dp" />
- Java代码重点是我在FragmentTabHost.setup()中把id改成了“R.id.realtabcontent”
 
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
public class TestFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, 
                ViewGroup container, Bundle savedInstanceState) {
        FragmentTabHost tabHost = new FragmentTabHost(getActivity());
        inflater.inflate(R.layout.test_fragment, tabHost);
        tabHost.setup(getActivity(), 
                      getChildFragmentManager(), R.id.realtabcontent);
        tabHost.addTab(tabHost.newTabSpec("simple")
            .setIndicator("Simple"), DummySectionFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec("contacts")
            .setIndicator("Contacts"), DummySectionFragment.class, null);
        return tabHost;
    }
    /**
     * A dummy fragment representing a section of the app, 
     * but that simply displays dummy text.
     */
    public static class DummySectionFragment extends Fragment {
        private static int count = 0;
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_section_dummy, 
                   container, false);
            ((TextView) rootView.findViewById(android.R.id.text1))
                    .setText("Dummy Section " + count++);
            return rootView;
        }
    }
}