你好,我正在搜索一个使用片段创建我的自定义选项卡栏(在底部)的好例子。
早些时候我是使用Activities编写的,但是在Android3中。*它被弃用了,我需要使用片段来完成这项工作。
下面是我编写的创建自定义选项卡栏的代码:
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);
}也许有人可以分享一些关于这方面的信息。
谢谢。
发布于 2012-04-04 14:03:38
开发者网站上有一大堆关于如何做到这一点的例子。请参阅FragmentTabs.java,以及页面。
如果你需要一步一步的学习,这也是一个不错的。
发布于 2012-04-04 14:14:39
我会尝试将Actionbarsherlock集成到您的项目中。它让你可以在安卓2.x以下的所有版本中使用蜂巢和冰激凌三明治的新TabApi。它使得添加标签非常容易,你的应用程序将遵循Android设计指南,看起来真的像Android应用程序。
https://stackoverflow.com/questions/10005561
复制相似问题