我正在尝试创建一个在Home_Tab Activity中具有标签视图的Android应用程序。 它有4个标签。我想对视图进行一些修改,也就是说,当我点击第一个标签时,它会在该标签下显示4个子标签。如何创建它, 我的代码在下面给出
public class Home_tab extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_main);
Resources ressources = getResources();
TabHost tabHost = getTabHost();
// Android tab
Intent intentAndroid = new Intent().setClass(this, CoalActivity.class);
TabSpec tabSpecAndroid = tabHost
.newTabSpec("Android")
.setIndicator("", ressources.getDrawable(R.drawable.tab_dis))
.setContent(intentAndroid);
// Apple tab
Intent intentApple = new Intent().setClass(this, EnergyActivity.class);
TabSpec tabSpecApple = tabHost
.newTabSpec("Apple")
.setIndicator("", ressources.getDrawable(R.drawable.tab_foc))
.setContent(intentApple);
// Windows tab
Intent intentWindows = new Intent().setClass(this, PowerActivity.class);
TabSpec tabSpecWindows = tabHost
.newTabSpec("Windows")
.setIndicator("", ressources.getDrawable(R.drawable.tab_nor))
.setContent(intentWindows);
// Blackberry tab
Intent intentBerry = new Intent().setClass(this, TopNewsActivity.class);
TabSpec tabSpecBerry = tabHost
.newTabSpec("Berry")
.setIndicator("", ressources.getDrawable(R.drawable.tab_sel))
.setContent(intentBerry);
// add all tabs
tabHost.addTab(tabSpecAndroid);
tabHost.addTab(tabSpecApple);
tabHost.addTab(tabSpecWindows);
tabHost.addTab(tabSpecBerry);
//set Windows tab as default (zero based)
tabHost.setCurrentTab(0);
}
}
答案 0 :(得分:1)
您需要再次创建类(CoalActivity)扩展tabactivity。并创建新的标签规范 简单.............