我在我的应用程序中包含了一个FragmentTabHost。在xml布局中,FragmentTabHost没有出现在xml布局中。它显示以下内容:
Rendering problems:
Exception raised during rendering:No tab known for tag null
story_tab.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.app.FragmentTabHost
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tab_host">
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
StoryTab.java:
public class StoryTab extends AppCompatActivity {
FragmentTabHost tabHost;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.story_tab);
tabHost=(FragmentTabHost) findViewById(R.id.tab_host);
tabHost.setup(getApplicationContext(), getSupportFragmentManager(), R.id.tabcontent);
tabHost.addTab(tabHost.newTabSpec("Stories").setIndicator("Stories"),StoryRecyclerLayout.class,savedInstanceState);
tabHost.addTab(tabHost.newTabSpec("Publish").setIndicator("Publish"),StoryRecyclerLayout.class,savedInstanceState);
}
}