【问题标题】:I want to set image and also text on tab [closed]我想在标签上设置图像和文本[关闭]
【发布时间】:2011-11-26 04:33:29
【问题描述】:
TabSpec spec1 = tabHost.newTabSpec("Tab1");
spec1.setIndicator("Tab1", getResources().getDrawable(R.drawable.news) );
Intent in1 = new Intent(this, Act1.class);
spec1.setContent(in1);

我确实使用了此代码。但是当我使用此代码时,图像未显示在选项卡上,仅显示文本。所以请告诉我任何建议。此代码仅适用于一个选项卡。

【问题讨论】:

  • 什么不起作用?你得到什么错误?
  • 希望您将 tabspec spec1 添加到 tabHost?

标签: android


【解决方案1】:

这样做:-

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);
        } 

【讨论】:

    猜你喜欢
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    • 2013-07-14
    • 2022-06-13
    • 1970-01-01
    • 2017-01-22
    相关资源
    最近更新 更多