简单的问题(我猜)。我有这个标签的默认谷歌教程代码:
intent = new Intent().setClass(this, About.class);
spec = tabHost.newTabSpec("albums").setIndicator("About")
.setContent(intent);
tabHost.addTab(spec);
for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50;
}
我想知道 - 是否可以通过在现有作品中添加代码行来改变文本位置和(或)背景,而不是重新开始一切?谢谢!
所以是的:文本位置和自定义背景(html颜色)。我该怎么做?谢谢!
请注意,请不要开始删除其他教程的链接,这对我来说很难理解。 :/
答案 0 :(得分:0)
我找到了我正在寻找的代码。这是我的Tabs.java活动的完整代码:
package com.xjcdi.name;
import com.xjcdi.exploringvilnius.R;
public class Tabs extends TabActivity implements OnTabChangeListener {
TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setOnTabChangedListener(this);
Resources res = getResources(); // Resource object to get drawables
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, Places.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Places")
.setContent(intent);
tabHost.addTab(spec);
for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50;
}
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
// Do the same for the other tabs
intent = new Intent().setClass(this, About.class);
spec = tabHost.newTabSpec("albums").setIndicator("About")
.setContent(intent);
tabHost.addTab(spec);
for (int i = 1; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50;
}
intent = new Intent().setClass(this, Artistai.class);
spec = tabHost.newTabSpec("songs").setIndicator("Map")
.setContent(intent);
tabHost.addTab(spec);
for (int i = 2; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50;
}
intent = new Intent().setClass(this, Map.class);
spec = tabHost.newTabSpec("songs").setIndicator("History")
.setContent(intent);
tabHost.addTab(spec);
for (int i = 3; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50;
}
tabHost.setCurrentTab(0);
}
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#000000"));
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#c1902d"));
}
}