简体   繁体   English

自定义标签内容

[英]Custom Tab Content

I made custom tabs using this tutorial: http://joshclemm.com/blog/?p=136 我使用此教程制作了自定义标签: http : //joshclemm.com/blog/?p=136

I have them completely customized and looking nice, but now I don't know how to add content to the tabs. 我已经对它们进行了完全自定义并且看起来不错,但是现在我不知道如何向选项卡添加内容。 I don't even know where to start with the way this code is written, any help? 我什至不知道该代码的编写方式从哪里开始,有帮助吗? Thanks. 谢谢。

This is the code that I think sets the content: 我认为这是设置内容的代码:

private void setupTab(final View view, final String tag) {
    View tabview = createTabView(mTabHost.getContext(), tag);

    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
        public View createTabContent(String tag) {return view;}
    });
    mTabHost.addTab(setContent);

}

I don't know what this is doing with "TabContentFactory" 我不知道“ TabContentFactory”在做什么

Try following the tutorial given on the android website . 尝试按照android网站上给出教程进行操作 Combined with the tutorial you used, it should give you completely what you want. 结合您使用的教程,它应该可以完全为您提供所需的内容。

Specifically, to add content to to each tab you add and activity to each tab like so: 具体来说,要将内容添加到每个选项卡,将活动添加到每个选项卡,如下所示:

spec = tabHost.newTabSpec("artists").setIndicator("Artists",
                  res.getDrawable(R.drawable.ic_tab_artists))
              .setContent(intent);
tabHost.addTab(spec);

Look at this: 看这个:

private void addActivityTab(int labelResId, int iconResId, Intent intent) {
    String tabLabel = getString(labelResId);        
    View indicator = View.inflate(this, R.layout.simple_tab_spec, null);        
    ImageView icon = (ImageView) indicator.findViewById(R.id.simple_tab_spec_icon);
    icon.setImageResource(iconResId);       
    TabSpec tabSpec = tabHost.newTabSpec(tabLabel).setIndicator(indicator).setContent(intent);
    tabHost.addTab(tabSpec); }

The first argument is the title of your tab item, the second argument is the background image of your tab item. 第一个参数是选项卡项目的标题,第二个参数是选项卡项目的背景图像。 You should create an intent object to set the parameters and the target activity. 您应该创建一个意图对象来设置参数和目标活动。

I too followed the same blog and was facing problem, while adding the Intent's. 在添加Intent的同时,我也关注了同一博客并面临问题。 So, finally I fixed it myself. 所以,最后我自己修复了它。 What I did is, 我所做的是

1.) public class CustomTabActivity extends Activity here I changed it to extend TabActivity 1.) public class CustomTabActivity extends Activity在这里我将其更改为extend TabActivity

2.) Just add the content using Intent 2.)只需使用Intent添加内容

Intent intent = new Intent().setClass(this, Hello.class);
        TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);

That's it and it worked. 就这样,它奏效了。 Hope this works for you too. 希望这对您也有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM