您好,我正在使用片段搜索创建自定义选项卡栏(位于底部)的一个很好的示例。使用支持包中的片段创建选项卡栏
早些时候我已经使用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