我在抽屉里创建了一个TabHost
。这意味着我创建了3个Fragment
和xml
个文件:ExhibitorFragment
,TabInternationalFragment
和TabLocalFragment
。现在的问题是,我看不到我的tabwidget在Toolbar
下,即使它在任何两个片段中显示设计xml
。Tabwidget在android studio的工具栏/导航栏下不可见
下面是我ExhibitorFragment.java代码:
public class ExhibitorFragment extends Fragment{
public ExhibitorFragment() {
// Required empty public constructor
}
private FragmentTabHost mTabHost;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mTabHost = new FragmentTabHost(getActivity());
mTabHost.setup(getActivity(), getChildFragmentManager(), R.layout.fragment_exhibitor);
Bundle arg1 = new Bundle();
arg1.putInt("Arg for Frag1", 1);
mTabHost.addTab(mTabHost.newTabSpec("Tab1").setIndicator("Frag Tab1"),
TabInternationalFragment.class, arg1);
Bundle arg2 = new Bundle();
arg2.putInt("Arg for Frag2", 2);
mTabHost.addTab(mTabHost.newTabSpec("Tab2").setIndicator("Frag Tab2"),
TabLocalFragment.class, arg2);
return mTabHost;
}
@Override
public void onDestroyView() {
super.onDestroyView();
mTabHost = null;
}
}
fragment_exhibitor.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.guitarista.citem.Example">
<TabHost 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" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/International"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<FrameLayout
android:id="@+id/Local"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
</LinearLayout>
</TabHost>
</FrameLayout>
的TabInternationalFragment
和TabLocalFragment
设置为默认为他们尊敬的xml
创建相同的时(fragment_tab_international,fragment_tab_local)。
我有渲染问题。这是正常的吗? – SovietSenpai
是的,这是完全正常的....布局将只在运行时可见 – qwertygamer
仍然无法工作:( – SovietSenpai