main.xml

  <?xml version="1.0" encoding="utf-8"?>
  <TabHost android: />
               </LinearLayout>
           </FrameLayout>
       </RelativeLayout>
  </TabHost>

  TabDemo1

  package com.focusmobi.TabDemo1;

  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TabHost;

  public class TabDemo1 extends Activity {
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle icicle) {
           super.onCreate(icicle);
         
           setContentView(R.layout.main);
           setTitle("TabWidget Demo");
         
           TabHost tabs = (TabHost) findViewById(R.id.tabhost);
           tabs.setup();
         
           TabHost.TabSpec spec = tabs.newTabSpec("tab1");
           spec.setContent(R.id.tab1);
           spec.setIndicator("主页");
           tabs.addTab(spec);
         
           spec = tabs.newTabSpec("tab2");
           spec.setContent(R.id.tab2);
           spec.setIndicator("经济");
           tabs.addTab(spec);
         
           spec = tabs.newTabSpec("tab3");
           spec.setContent(R.id.tab3);
           spec.setIndicator("汽车");
           tabs.addTab(spec);
         
           spec = tabs.newTabSpec("tab4");
           spec.setContent(R.id.tab4);
           spec.setIndicator("科技");
           tabs.addTab(spec); 
          
           tabs.setCurrentTab(0);
       }
   }

补充: 在设计tab时,有很多内容是写死的。注意看上面红色标记的内容。by 喜糖

相关文章:

  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2021-12-08
猜你喜欢
  • 2021-12-29
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2021-04-23
  • 2021-06-07
相关资源
相似解决方案