2017-03-15 4 views

Répondre

0

Essayez ceci,

public void onTabChanged(String tabId) { 
    // TODO Auto-generated method stub 
    for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++) 
    { 
     View view = mTabHost.getTabWidget().getChildTabViewAt(i); 
     if (view != null) { 

      // get title text view 
      TextView textView = (TextView)view. findViewById(R.id.tab_title); 
      textView.setTextColor(Color.WHITE); 
     } 

    } 
    title.setTextColor(Color.RED); 
} 
+0

Comment puis-je ajouter TextView tab_title dans TabWidget? –

0

Regardez ce documentation, à l'intérieur onCreate() méthode pour définir la couleur d'arrière-plan initial de l'onglet sélectionné et non sélectionné.

for(int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { 
     tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117")); 
} 
    tabHost.getTabWidget().setCurrentTab(1); 
    tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#C35817")); 

Mettre en œuvre la OnTabChangeListener à l'activité en cours, puis remplacer la méthode onTabChanged(). Dans cette méthode, écrivez le code ci-dessous pour définir la couleur de l'onglet sélectionné et de l'onglet non sélectionné.

@Override 
public void onTabChanged(String tabId) { 
    for(int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){ 
     tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117")); 
    } 

    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#C35817")); 
} 

Mise à jour

Change vous couleur du texte onglet:

  • via un fichier xml:

    <android.support.design.widget.TabLayout 
        app:tabTextColor="@color/your_color" 
        app:tabSelectedTextColor="@color/your_color"/> 
    
  • Via Code:

    tabLayout.setTabTextColors(
        ContextCompat.getColor(context, R.color.your_unselected_tab_text_color), 
        ContextCompat.getColor(context, R.color.your_selected_tab_text_color) 
    ); 
    
+0

Non. Je veux changer la couleur du texte, pas la couleur de l'onglet. Mais j'apprécie votre aide. Savez-vous comment changer la couleur du texte de l'indicateur, lorsque je sélectionne un onglet? –