How to add tabhost with navigation drawer?

前端 未结 2 1519
野趣味
野趣味 2020-12-11 12:47

I am new to android development,I used navigation drawer from this http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

Now I want to a

2条回答
  •  抹茶落季
    2020-12-11 13:11

    You not added any view for your TabHost View. Try to add view in your setIndicator() method like this.

    public class HomeFragment extends Fragment {
    private FragmentTabHost mTabHost;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        mTabHost = new FragmentTabHost(getActivity());
        mTabHost.setup(getActivity(), getChildFragmentManager(),
                R.layout.fragment_home);
        Bundle arg1 = new Bundle();
        arg1.putInt("Arg for Frag1", 1);
        View view = LayoutInflater.from(getActivity()).inflate(
                R.layout.yourview1, null);
        mTabHost.addTab(mTabHost.newTabSpec("Tab1").setIndicator(view),
                PhotosActivity.class, arg1);
        Bundle arg2 = new Bundle();
        arg2.putInt("Arg for Frag2", 2);
        View view = LayoutInflater.from(getActivity()).inflate(
                R.layout.yourview2, null);
        mTabHost.addTab(mTabHost.newTabSpec("Tab2").setIndicator(view),
                PhotosActivity.class, arg2);
        return mTabHost;
    }
    
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mTabHost = null;
    }
    

提交回复
热议问题