public class MainActivity extends AppCompatActivity { private TabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTabHost=(TabHost)findViewById(android.R.id.tabhost); mTabHost.setup(); // addTab("zhuye",R.layout.zhuye, Activity_zhuye.class); // addTab("tianjia",R.layout.zhuye, Activity_tianjia.class); // addTab("wode",R.layout.wode, Activity_wode.class); addTab("zhuye",R.layout.zhuye); addTab("tianjia",R.layout.tianjia); addTab("wode",R.layout.wode); mTabHost.setCurrentTab(0); } // private void addTab(String label, int drawableId, Class act) { // TabHost.TabSpec spec = mTabHost.newTabSpec(label); // View tabIndicator = getLayoutInflater().inflate(drawableId, null); // spec.setIndicator(tabIndicator); // // Intent intent = new Intent(getApplicationContext(),act); // spec.setContent(intent); // mTabHost.addTab(spec); // } private void addTab(String label, int drawableId) { TabHost.TabSpec spec = mTabHost.newTabSpec(label); View tabIndicator = getLayoutInflater().inflate(drawableId, null); spec.setIndicator(tabIndicator); spec.setContent(R.id.content); mTabHost.addTab(spec); } }