can anyone give sample code for TabHost in Android?

前端 未结 4 2028
春和景丽
春和景丽 2021-02-10 06:50

I need sample code to create TabHost in android. can anyone help me.

4条回答
  •  被撕碎了的回忆
    2021-02-10 07:38

    activity_main.xml contains

    
    
    
        
    
            
    
            
    
                
            
        
    
    
    

    and java code is

    TabHost tabHost = getTabHost();
    
            TabSpec spec;
    
            Intent intent;
    
            //Home Tab
            View view1 = LayoutInflater.from(MainActivity.this).inflate(R.layout.home, null);
    
            intent = new Intent(MainActivity.this, Firstclass.class);
    
            spec = tabHost.newTabSpec("HOME").setIndicator(view1)
                    .setContent(intent);
    
            tabHost.addTab(spec);
    
            //Calendar Tab
            View view2 = LayoutInflater.from(MainActivity.this).inflate(R.layout.calendar_tab, null);
    
            intent = new Intent(MainActivity.this, Calendar.class);
    
            spec = tabHost.newTabSpec("CALENDAR").setIndicator(view2)
                    .setContent(intent);
    
            tabHost.addTab(spec);
    

提交回复
热议问题