2011-11-25 36 views
1
TabSpec spec1 = tabHost.newTabSpec("Tab1"); 
spec1.setIndicator("Tab1", getResources().getDrawable(R.drawable.news)); 
Intent in1 = new Intent(this, Act1.class); 
spec1.setContent(in1); 

我確實使用過這個代碼。僅適用於一個選項卡。我想設置圖像,也是選項卡上的文字

+0

什麼是不工作?你會得到什麼錯誤? – kaspermoerch

+1

希望你將tabspec spec1添加到tabHost? – user994886

回答

2

這樣做: -

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); 
     } 
相關問題