【发布时间】:2013-10-11 07:24:24
【问题描述】:
我在我的应用程序中使用了禁忌,要求是选择任何选项卡时选项卡指示符的颜色应更改,我在How to set Tab View Indicator background color in Android但我不明白 这是我的代码:
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, HomePage.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("tabOne");
spec.setContent(intent);
spec.setIndicator("Home");
tabHost.addTab(spec);
// Squash the tab a little bit horizontally
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 40;
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 50;
// Bump the text size upll.getChildAt(0);
// Do the same for the other tabs
intent = new Intent().setClass(this, MoteIt.class);
spec = tabHost.newTabSpec("tabTwo");
spec.setContent(intent);
spec.setIndicator("moteit");
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 40;
intent = new Intent().setClass(this, Lifeline.class);
spec = tabHost.newTabSpec("tabThree");
spec.setContent(intent);
spec.setIndicator("lifeline");
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 40;
intent = new Intent().setClass(this, CircleOfTrust.class);
spec = tabHost.newTabSpec("tabfour");
spec.setContent(intent);
spec.setIndicator("Cot");
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 40;
intent = new Intent().setClass(this, Search.class);
spec = tabHost.newTabSpec("tabFive");
spec.setContent(intent);
spec.setIndicator("Search");
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 40;
tabHost.getTabWidget().setStripEnabled(true);
tabHost.setCurrentTab(0);
提前致谢
【问题讨论】:
标签: android android-layout android-tabhost android-tabs