WEB开发网
开发学院手机开发Android 开发 Android 标签/TabActivity 深度研究 阅读

Android 标签/TabActivity 深度研究

 2010-06-19 17:46:00 来源:WEB开发网   
核心提示:getResources().getDrawable(R.drawable.beijing_small)).setContent(R.id.view2));tHost.addTab(tHost.newTabSpec(Tab3).setIndicator("Tab 3").setContent(R.i
getResources().getDrawable(R.drawable.beijing_small)).setContent(R.id.view2));

tHost.addTab(tHost.newTabSpec(Tab3).setIndicator("Tab 3").setContent(R.id.view3));

tHost.addTab(tHost.newTabSpec(Tab4).setIndicator("Tab 4").setContent(R.id.view4));

public static final String Tab1 = "Tab1";

public static final String Tab2 = "Tab2";

public static final String Tab3 = "Tab3";

public static final String Tab4 = "Tab4";

public static final String Tab5 = "Tab5";

tHost.addTab(tHost.newTabSpec(Tab1).setIndicator("Tab 1", getResources().getDrawable(R.drawable.icon)).setContent(R.id.view1));

tHost.addTab(tHost.newTabSpec(Tab2).setIndicator("Tab 2", getResources().getDrawable(R.drawable.beijing_small)).setContent(R.id.view2));

tHost.addTab(tHost.newTabSpec(Tab3).setIndicator("Tab 3").setContent(R.id.view3));

tHost.addTab(tHost.newTabSpec(Tab4).setIndicator("Tab 4").setContent(R.id.view4));

* 设定监听器 用于监听 标签间切换事件

Java代码

tHost.setOnTabChangedListener(new OnTabChangeListener(){

@Override

public void onTabChanged(String tabId) {

// TODO Auto-generated method stub

}

});

tHost.setOnTabChangedListener(new OnTabChangeListener(){

@Override

public void onTabChanged(String tabId) {

// TODO Auto-generated method stub

}

});

* emulator 运行情况:

2. 在 *.java 中定义标签所需布局

Java代码

public class CustomLayout implements TabHost.TabContentFactory {

Activity activity;

LayoutInflater inflaterHelper;

LinearLayout layout;

public CustomLayout (Activity a) {

activity = a;

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:Android 标签 TabActivity

编辑录入:coldstar [复制链接] [打 印]
赞助商链接