我想设置图像和文字上的标签 [英] I want to set image and also text on tab

查看:143
本文介绍了我想设置图像和文字上的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TabSpec spec1 = tabHost.newTabSpec("Tab1");
spec1.setIndicator("Tab1", getResources().getDrawable(R.drawable.news) );
Intent in1 = new Intent(this, Act1.class);
spec1.setContent(in1);

我没有使用,当我用这个$ C $这code.but c中的形象不是唯一选项卡上的文字显示都showing.so请告诉我,只有这code任何suggestion.and一个标签

I did use this code.but when i using this code the image not show on the tab only text are showing.so please tell me any suggestion.and this code only for one tab.

推荐答案

这样做: -

TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");

firstTabSpec.setIndicator("Current").setContent(new Intent(this,Common.class));       secondTabSpec.setIndicator("24Hour").setContent(new Intent(this,Commonsecond.class));
thirdTabSpec.setIndicator("48Hour").setContent(new Intent(this,Commonthird.class));

tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thirdTabSpec);



for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
{
TextView tv =(TextView)tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
          tv.setTextColor(Color.BLACK);
          tv.setPadding(10, 10, 10, 15);
          tv.setTextSize((float) 20.0);
          tv.setTypeface(null, Typeface.BOLD);
          tv.setBackgroundResource(R.drawable.icon);
          tv.setHeight(100);
          tv.setWidth(100);
        } 

这篇关于我想设置图像和文字上的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆