question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for TabLayout from Android Design Support library.

See original GitHub issue

Thank you for this amazing library.

I am having an issue with the TabLayout widget introduced in the new Design Support Library launched by the Android team. The textviews in the tabs are not responding to the font change.

I have followed the steps from http://chrisjenx.com/calligraphy-2-0-0/. I am using v2.1.1 of your library. Am I missing something?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:33 (11 by maintainers)

github_iconTop GitHub Comments

20reactions
scottyabcommented, Mar 18, 2016

Used CalligraphyTypefaceSpan in the getPageTitle() didn’t work for me using com.android.support:design:23.2.0. But the customView version works fine if not a little fugly. If any one is looking for code sample on how to apply a custom view with the fontPath defined heres want I used.

private void initTabs() {
        TabPagerAdapter adapter = new TabPagerAdapter(getSupportFragmentManager());
        pager.setAdapter(adapter);
        tabLayout.setupWithViewPager(pager);
        //tabLayout it doesn't respond to style attribute 'tabTextAppearance' so we have to use customview
        for (int i = 0; i < adapter.getCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null) {
                tab.setCustomView(R.layout.tab_text);
                tab.setText(adapter.getPageTitle(i));
            }
        }
    }

Below is the custom view - res/layout/tab_text.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- needs this container to work with the Tablayout -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center">

 <TextView
        android:id="@android:id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center"
        android:maxLines="2"
        app:fontPath="**your custom font here**"
        tools:ignore="MissingPrefix"
        tools:text="User Profile" />
</FrameLayout>
7reactions
srinivaskrifycommented, Dec 2, 2015

Sorry to open this thread again, I think this might be helpful

@Override public CharSequence getPageTitle(int position) { String title = mFragmentTitleList.get(position); CalligraphyTypefaceSpan typefaceSpan = new CalligraphyTypefaceSpan(TypefaceUtils.load(activity.getAssets(), “fonts/OpenSans-Semibold.ttf”)); SpannableStringBuilder s = new SpannableStringBuilder(); s.append(title); s.setSpan(typefaceSpan, 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return SpannableString.valueOf(s); }

I am using tablayout with view pager and it worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Design Support Library - Android Developers Blog
The Design library's TabLayout implements both fixed tabs, where the view's width is divided equally between all of the tabs, as well as ......
Read more >
Android Design Support Library - Tablayout with toolbar
So the question remains, how to I make my individual fragments update the options available in the options menu of the toolbar? activity_main....
Read more >
Material Design Tabs with Android Design Support Library
For creating Tabs, we use the TabLayout widget class. This is a new widget, part of the Design Support Library.
Read more >
Support Library Features Guide - Android Developers
Views, dialogs, and widgets · CardView - A support library custom class for creating Material Design style display cards.
Read more >
TabLayout with Android Design Support Library
TabLayout with Android Design Support Library ... Switching between different views in your app via tabs is not a new concept to material...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found