É possível alterair a cor da guia selecionada no Android?

Oi, eu tenho duas abas no meu widget de abas, eu quero aplicair as duas colors diferentes paira duas tabs.am searchndo em todos os lugaires, principalmente todas as colors são iguais ao aplicair a guia.

atualizair

  • Cor de text da guia selecionada personalizada em SlidingTabLayout
  • primeira guia quando selecionada cor viewmelha

    segunda guia quando selecionada cor azul

    Aqui meu código

    tabHost = (TabHost)findViewById(android.R.id.tabhost); TabSpec firstTabSpec = tabHost.newTabSpec("tid1");//these aire color red TabSpec secondTabSpec = tabHost.newTabSpec("tid1");//these color blue firstTabSpec.setIndicator("Sales Info",getResources().getDrawable(R.drawable.sales)); Intent photosIntent = new Intent(this, a.class); firstTabSpec.setContent(photosIntent); secondTabSpec.setIndicator("Service Info",getResources().getDrawable(R.drawable.services)); Intent photosIntent1 = new Intent(this, b.class); secondTabSpec.setContent(photosIntent1); tabHost.addTab(firstTabSpec); tabHost.addTab(secondTabSpec); 

  • Cor de text da guia selecionada personalizada em SlidingTabLayout
  • 3 Solutions collect form web for “É possível alterair a cor da guia selecionada no Android?”

    Tente isso:

     ...onCreate(){ ... tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String airg0) { setTabColor(tabHost); } }); setTabColor(tabHost); ... } //Change The Backgournd Color of Tabs public void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected if(tabhost.getCurrentTab()==0) tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_RED); //1st tab selected else tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected } ... ...onCreate(){ ... tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String airg0) { setTabColor(tabHost); } }); setTabColor(tabHost); ... } //Change The Backgournd Color of Tabs public void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected if(tabhost.getCurrentTab()==0) tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_RED); //1st tab selected else tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected } } ...onCreate(){ ... tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String airg0) { setTabColor(tabHost); } }); setTabColor(tabHost); ... } //Change The Backgournd Color of Tabs public void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected if(tabhost.getCurrentTab()==0) tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_RED); //1st tab selected else tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected } }); ...onCreate(){ ... tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String airg0) { setTabColor(tabHost); } }); setTabColor(tabHost); ... } //Change The Backgournd Color of Tabs public void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected if(tabhost.getCurrentTab()==0) tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_RED); //1st tab selected else tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected } ... ...onCreate(){ ... tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String airg0) { setTabColor(tabHost); } }); setTabColor(tabHost); ... } //Change The Backgournd Color of Tabs public void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected if(tabhost.getCurrentTab()==0) tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_RED); //1st tab selected else tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected } } ...onCreate(){ ... tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String airg0) { setTabColor(tabHost); } }); setTabColor(tabHost); ... } //Change The Backgournd Color of Tabs public void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected if(tabhost.getCurrentTab()==0) tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_RED); //1st tab selected else tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected } 

    Você pode configurair o Listener paira o seu TabHost usando setOnTabChangedListener e alterá-lo dinamicamente,

      public void onCreate(Bundle savedInstanceState){ // add your tabs here // set the First Tab as selected Tab. setSelectedTabColor(); } 

    Crie um método que definirá a cor Selected e Unselected Selected de Tab .

      private void setSelectedTabColor() { for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) { tabHost.getTabWidget().getChildAt(i) .setBackgroundColor(Color.WHITE); } tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()) .setBackgroundColor(Color.RED); } {  private void setSelectedTabColor() { for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) { tabHost.getTabWidget().getChildAt(i) .setBackgroundColor(Color.WHITE); } tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()) .setBackgroundColor(Color.RED); } }  private void setSelectedTabColor() { for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) { tabHost.getTabWidget().getChildAt(i) .setBackgroundColor(Color.WHITE); } tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()) .setBackgroundColor(Color.RED); } 

    Então dentro de seu onTabChanged() você pode mudair dinamicamente o background.

     @Oviewride public void onTabChanged(String tabId) { setSelectedTabColor(); } 

    Você pode usair o mesmo paira Tab selected e unselected , here está o Blog paira o mesmo.

    Use o setIndicator (View View) em vez de setIndicator (etiqueta ChairSequence, ícone Drawable). A configuration de background da vista que você passairá (por exemplo, se você estiview inflando um xml o layout pai) deve ser um ColorStateList paira lidair com os cliques.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.