0

J'utilise MaterialTabHost pour afficher les onglets. Je voulais changer la police du MaterialTabHost quand onTabSelected. J'ai essayé d'obtenir le textview de la même chose. mais je ne peux pas comprendre. J'ai référé https://github.com/neokree/MaterialTabs. toute aide serait appriciée.Comment changer la police de texte dans MaterialTabHost dans Android?

Voici mon XML.

    <!-- for Text Tabs --> 
        <it.neokree.materialtabs.MaterialTabHost 
         android:id="@+id/materialTabHost_MainActivity" 
         android:layout_width="match_parent" 
         android:layout_height="48dp" 
         android:animateLayoutChanges="false" 
         app:accentColor="@color/white" 
         app:primaryColor="@color/main_blue_light" 
         app:textColor="@color/white" 

         /> 

alors comment pouvons-nous changer la police?

Répondre

0

Voici comment je change la police du texte dans l'onglet quand il est créer:

Typeface fontRobotoRegular = Typeface.createFromAsset(getAssets(),"font/RobotoCondensed-Regular.ttf"); 
MaterialTab tab = new MaterialTab(getApplicationContext(), false); 
View tabView = tab.getView(); 
TextView text = (TextView) tabView.findViewById(R.id.text); 
tab.setText(pagerAdapter.getPageTitle(i)); 
text.setTypeface(fontRobotoRegular); 
tab.setTabListener(this); 
tabHost.addTab(tab); 

Donc, si vous voulez changer la police lorsque l'onglet est sélectionnée, vous pouvez faire quelque chose comme ça sur onPageSelected de votre ViewPager:

public void onPageSelected(int position) { 
    ... 
    Typeface fontBold = Typeface.createFromAsset(getAssets(), "font/RobotoCondensed-Bold.ttf"); 
    TextView text = (TextView) tabs.getCurrentTab().getView().findViewById(R.id.text); 
    text.setTypeface(fontBold); 
    ... 
}