How can i set custom typeface for tablayout titles in android? i want to use Yekan font for titles and i tried and searched but didn't find any way...
Java :
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("ورود"));
tabLayout.addTab(tabLayout.newTab().setText("ثبت نام"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
final PagerAdapter adapter = new PagerAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
Xml :
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e7e7e7"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingBottom="30dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:paddingTop="30dp" />
Is there any way to i set for example :
Typeface yekan = Typeface.createFromAsset(getAssets(), "fonts/yekan.ttf");
typeface for my tabs :
tabLayout.addTab(tabLayout.newTab().setText("ورود"));
tabLayout.addTab(tabLayout.newTab().setText("ثبت نام"));
You can try this
Create an xml layout named
custom_tab.xml
under res ⇒ layout. In this layout we have defined the custom view for the tab.custom_tab.xml
Now Open Activity.java and modify the code as below.