tabHost主程序activity_main:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
/* 去除标签下方的白线 ,底部-5刚好可以把底下的白线抹掉,不减保持原样*/
/* mTabHost.setPadding(mTabHost.getPaddingLeft(),
mTabHost.getPaddingTop(), mTabHost.getPaddingRight(),
mTabHost.getPaddingBottom() - 5);*/
Intent layout2intent = new Intent();
layout2intent.setClass(this, Layout2.class);
/*
Bundle bundle2 = new Bundle();
bundle2.putString("SerialPortData", GetSerialPortData); //
layout2intent.putExtras(bundle2);
*/
TabHost.TabSpec layout2spec = mTabHost.newTabSpec("layout2");
layout2spec.setIndicator("第二个标签",getResources().getDrawable(android.R.drawable.stat_sys_phone_call)); //设置tab1的字和背景图,需要用getResources()得到图片的资源路径
layout2spec.setContent(layout2intent);//设置tab2对应的framelay内容
mTabHost.addTab(layout2spec);//addTab中已经包含了点击事件
}
tab程序Layout2.class:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layout2);
textView = (TextView) findViewById(R.id.text2);
layout2Intent =getIntent();
bundle = layout2Intent.getExtras();
Getdata = bundle.getString("SerialPortData");
textView.append(Getdata);
}