comment puis-je changer la couleur du texte de l'indicateur, lorsque l'onglet est sélectionné. Je veux avoir une différence entre 2 onglets. MerciDéfinir la couleur du texte pour l'indicateur de TabHost, quand il est sélectionné
Répondre
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);
}
Comment puis-je ajouter TextView tab_title dans TabWidget? –
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) );
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? –
S'il vous plaît fournir quelques codes afin que nous puissions vous aider. – MohammedAlSafwan