Fragments overlapping each other

后端 未结 4 1048
囚心锁ツ
囚心锁ツ 2020-12-31 02:01

I have an action bar with 3 tabs, each tab opens a fragment. The third tab, \"Catalog\", has a list: \"enter

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 02:42

    You can try like this for tabs..

       public class Tabs extends TabActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tabs);
        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
       // Intent intent;  // Reusable Intent for each tab
        // Create an Intent to launch an Activity for the tab (to be reused)
        Intent intent1 = new Intent().setClass(this, Social.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("app_name").setIndicator("Practice",
                          res.getDrawable(R.drawable.tab_social))
                      .setContent(intent1);
        tabHost.addTab(spec);
        tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.bbgg);
        // Do the same for the other tabs
        Intent intent2 = new Intent().setClass(this, Web.class);
        spec = tabHost.newTabSpec("application").setIndicator("Application",
                          res.getDrawable(R.drawable.tab_web))
                      .setContent(intent2);
        tabHost.addTab(spec);
        tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.bbgg);
        Intent intent3 = new Intent().setClass(this, Catalog.class);
        spec = tabHost.newTabSpec("toplinks").setIndicator("Top Links",
                          res.getDrawable(R.drawable.tab_catalog))
                      .setContent(intent3);
        tabHost.addTab(spec);
        tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.bbgg);
        tabHost.setCurrentTab(0);
    }
    }
    

    In your layout xml

        
      
     
     
     
    

提交回复
热议问题