Android TabHost 详细讲解(2)

package com.droidstouch.tabhost;

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

public class Dome1Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo1);




//从布局文件中 获取到TabHost
TabHost tabHost = (TabHost) this.findViewById(R.id.tabs);
//安装TabHost
tabHost.setup();


// 下面定义两个选项卡

//获取一个新的TabHost.TabSpec,并关联到当前tab host
//参数:所需的选项卡标签
TabSpec pSpec = tabHost.newTabSpec("parent");
pSpec.setIndicator("父类", this.getResources().getDrawable(R.drawable.f_root));
pSpec.setContent(R.id.txtV1);



TabSpec subSpec = tabHost.newTabSpec("sub");
subSpec.setIndicator("子类", this.getResources().getDrawable(R.drawable.f_root));
subSpec.setContent(R.id.txtV2);


//添加选项卡到TabHost中
tabHost.addTab(pSpec);
tabHost.addTab(subSpec);

}
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/pxgss.html