2011-01-21 12 views

risposta

18

Il seguente codice ha funzionato per me:

tabHost.getTabWidget().setBackgroundResource(R.drawable.tabhost_bg); 
+1

nelle schede immagine sembra essere trasparente ... come hai fatto? Riesco a impostare lo sfondo, ma le mie schede sono visibili in alto con il colore grigio ... :( – Farhan

+2

È necessario impostare la visualizzazione con sfondo trasparente (o senza alcuno) come indicatore delle schede per far funzionare questa soluzione. – ernazm

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

ho usato di default drawable Android u possibile utilizzare ciò che si vuole

per l'impostazione di fondo della tabhost

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

Ciò imposterà l'immagine come sfondo delle singole schede. Voglio impostare l'immagine di sfondo sullo sfondo di tutte le schede [parte sotto le schede]. – neha

+0

modificato la mia risposta – ingsaurabh

+0

Questo 'imposta l'immagine di sfondo su tutto lo schermo e non solo sullo sfondo delle schede. – neha

10

provare questo

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