你好,我希望它可以幫助你。
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
host = getTabHost();
host.addTab(host.newTabSpec(Constants.TAG_TAB1).setIndicator(Constants.TAG_TAB1,getResources().getDrawable(R.drawable.img1)).setContent(new Intent(this, Activity1.class)));
host.addTab(host.newTabSpec(Constants.TAG_TAB2).setIndicator(Constants.TAG_TAB2,getResources().getDrawable(R.drawable.img2)).setContent(new Intent(this, Activity2.class);
host.addTab(host.newTabSpec(Constants.TAG_TAB3).setIndicator(Constants.TAG_TAB3,getResources().getDrawable(R.drawable.img3)).setContent(new Intent(this, Activity3.class)));
host.addTab(host.newTabSpec(Constants.TAG_TAB4).setIndicator(Constants.TAG_TAB4,getResources().getDrawable(R.drawable.img4)).setContent(new Intent(this, Activity4.class)));
host.setCurrentTab(0);
for(int i=0;i<host.getTabWidget().getChildCount();i++)
{
host.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
}
host.getTabWidget().getChildAt(host.getCurrentTab()).setBackgroundResource(android.R.color.transparent);// selected
host.setOnTabChangedListener(this);
}
@Override
public void onTabChanged(String tabId)
{
for(int i=0;i<host.getTabWidget().getChildCount();i++)
{
host.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
}
host.getTabWidget().getChildAt(host.getCurrentTab()).setBackgroundResource(android.R.color.transparent);// selected
}
製表符的一個快照值多於1000個單詞。 –