Unable to add Tabs inside Fragment of Navigation Drawer Android

前端 未结 1 1293
轮回少年
轮回少年 2021-01-02 14:50

1) I have followed the Navigation Drawer example in Android Developer Docs here developer.android.com/training/implementing-navigation/nav-drawer.

相关标签:
1条回答
  • 2021-01-02 15:20
    import android.app.ActionBar;
    import android.app.Fragment;
    import android.app.FragmentTransaction;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import cgg.gov.in.apps.eoffice.source.R;
    
    public class TestTabsinsideFragment extends Fragment
    {
        View rootView;
    
    public TestTabsinsideFragment () 
    {
        // Empty constructor required for fragment subclasses
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle     savedInstanceState)
    {   
    
    getActivity().getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    
    // Apply the layout for the fragment
    rootView = inflater.inflate(R.layout.approve_leaves, container, false);
    
    
    getActivity().setTitle("New tabbed layout inside Fragment :-) ");
    
    
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            // show the given tab
        }
    
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // hide the given tab
        }
    
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // probably ignore this event
        }
    };
    
    // Add 3 tabs, specifying the tab's text and TabListener
    for (int i1 = 0; i1 < 3; i1++) {
        getActivity().getActionBar().addTab(
                getActivity().getActionBar().newTab()
                .setText("Tab " + (i1 + 1))
                .setTabListener(tabListener));
    }
    
    
    return rootView;
    }
    

    I have fixed the problem myself. :D

    0 讨论(0)
提交回复
热议问题