您好,我正在使用片段搜索創建自定義選項卡欄(位於底部)的一個很好的示例。使用支持包中的片段創建選項卡欄
早些時候我已經使用Activities Groups編寫過這個,但是從android 3. *它已經被棄用了,我需要使用片段來做到這一點。
這裏是我寫的創建我的自定義標籤欄的代碼:
private void setTabs()
{
//Implementing strings
String publication = String.format("First");
String shop = String.format("Second");
//Adding tabs to TabActivity
//addTab(publication, R.drawable.ic_launcher, DisplayTestActivity.class);
//addTab(shop, R.drawable.ic_launcher, DisplayPushedTestActivity.class);
}
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
}
/**
*
* @param labelId, tab name
* @param drawableId, tab icon image
* @param c, responsible class
*/
/*
private void addTab(String labelId, int drawableId, Class<?> c)
{
TabHost tabHost = getTabHost(); // The activity TabHost
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
System.out.println(tabIndicator);
TextView title = (TextView) tabIndicator.findViewById(R.id.tab_bar_title);
System.out.println(labelId);
System.out.println(title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.tab_bar_icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
也許有人可以分享一些這方面的信息。
謝謝。
我已經在使用Action Bar Sherlock,並且還希望標籤欄 – Streetboy 2012-04-04 06:16:09