首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我们可以给标签设置一个背景图片吗?

问我们可以给标签设置一个背景图片吗?
EN

Stack Overflow用户
提问于 2011-01-21 15:37:14
回答 3查看 17.8K关注 0票数 10

我们可以像这样给标签设置一个背景图片吗?

​

​

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-01-21 16:14:23

下面的代码对我很有效:

代码语言:javascript
复制
 tabHost.getTabWidget().setBackgroundResource(R.drawable.tabhost_bg);
票数 18
EN

Stack Overflow用户

发布于 2011-01-21 15:49:32

尝尝这个

代码语言:javascript
复制
             getTabHost().addTab(getTabHost().newTabSpec("A")
                    //set the tab name
                    .setIndicator("A")
                    //Add additional flags to the intent (or with existing flags value).
                    .setContent(new Intent(this, A.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));      

            //for creating tab we need to pass tabSpec and tab name to setIndicator and pass intent to its 
                //setContent  to Tab Activity predefined method getTabHost then it will create tab
             getTabHost().addTab(getTabHost().newTabSpec("B")
                    //set the tab name
                        .setIndicator("B")

                         //Add additional flags to the intent (or with existing flags value).
                       .setContent(new Intent(this,B.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) );

getTabHost().addTab(getTabHost().newTabSpec("C")
                    //set the tab name
                        .setIndicator("C")

                         //Add additional flags to the intent (or with existing flags value).
                       .setContent(new Intent(this,C.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) );    


             getTabHost().getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.a);
 getTabHost().getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.b);
 getTabHost().getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.c);
票数 10
EN

Stack Overflow用户

发布于 2011-01-21 15:44:03

代码语言:javascript
复制
TabSpec generalTab = mTabHost.newTabSpec("general");
generalTab.setIndicator("General", getResources().getDrawable(android.R.drawable.ic_menu_preferences)).setContent(R.id.tabGeneral);

我已经使用了默认的android绘图,你可以使用你想要的任何东西

用于设置tabhost的背景

代码语言:javascript
复制
this.mTabHost = (TabHost)this.findViewById(R.id.tabHost);
    this.mTabHost.setBackgroundResource(R.drawable.back);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4756447

复制
相关文章

相似问题

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