首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用支持包中的片段创建选项卡栏

使用支持包中的片段创建选项卡栏
EN

Stack Overflow用户
提问于 2012-04-04 13:46:43
回答 2查看 6.3K关注 0票数 0

你好,我正在搜索一个使用片段创建我的自定义选项卡栏(在底部)的好例子。

早些时候我是使用Activities编写的,但是在Android3中。*它被弃用了,我需要使用片段来完成这项工作。

下面是我编写的创建自定义选项卡栏的代码:

代码语言:javascript
复制
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);
}

也许有人可以分享一些关于这方面的信息。

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-04 14:03:38

开发者网站上有一大堆关于如何做到这一点的例子。请参阅FragmentTabs.java,以及页面。

如果你需要一步一步的学习,这也是一个不错的。

票数 4
EN

Stack Overflow用户

发布于 2012-04-04 14:14:39

我会尝试将Actionbarsherlock集成到您的项目中。它让你可以在安卓2.x以下的所有版本中使用蜂巢和冰激凌三明治的新TabApi。它使得添加标签非常容易,你的应用程序将遵循Android设计指南,看起来真的像Android应用程序。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10005561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档