J'ai construit un TabHost
dans mon tiroir de navigation. Cela signifie que j'ai créé 3 Fragment
avec xml
fichiers chacun: ExhibitorFragment
, TabInternationalFragment
et TabLocalFragment
. Maintenant, le problème est, je ne peux pas voir mon tabwidget sous le Toolbar
même si elle affiche la conception xml
dans deux des fragments.Tabwidget pas visible sous la barre d'outils/navbar dans le studio android
ci-dessous est mon code pour 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>
Le TabInternationalFragment
et TabLocalFragment
sont définis par défaut lors de la création même que leur respecté xml
(fragment_tab_international, fragment_tab_local).
J'ai des problèmes de rendu. Est-ce normal? – SovietSenpai
Oui, c'est tout à fait normal .... La mise en page ne sera visible que dans l'exécution – qwertygamer
ne fonctionne toujours pas :( – SovietSenpai