2011-01-21 24 views

cevap

18
deneyin TabHost arka planını ayarlamak için size

istediğini kullanabilir varsayılan android çekilebilir kullandıkAşağıdaki kod benim için çalıştı:
tabHost.getTabWidget().setBackgroundResource(R.drawable.tabhost_bg); 
+1

için şeffaf görünüyor ... nasıl yaptın? Arka plan oluşturmayı başarabilirim ancak sekmelerim gri renkle üstte görünür ... :( – Farhan

+2

Bu özümün işe yaraması için sekmelerde göstergenin bir göstergesi olarak saydam arka planlı (veya hiç yok) görünümü ayarlamanız gerekir. – ernazm

1
TabSpec generalTab = mTabHost.newTabSpec("general"); 
generalTab.setIndicator("General", getResources().getDrawable(android.R.drawable.ic_menu_preferences)).setContent(R.id.tabGeneral); 

u

this.mTabHost = (TabHost)this.findViewById(R.id.tabHost); 
    this.mTabHost.setBackgroundResource(R.drawable.back); 
+0

Bu, resmi tek tek sekmelere arka plan olarak ayarlayacaktır. Arka plan resmini, tüm sekmelerin arka planına [sekmelerin altındaki bölüm] ayarlamak istiyorum. – neha

+0

cevabımı düzenledim – ingsaurabh

+0

Bu, 'arka plan görüntüsünü yalnızca ekranların arka planına değil, yalnızca sekmelerin arka planına göre ayarlar. – neha

10

bu

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