1

I'm trying to set up a text size from code, since this option does not exist does anyone have an idea how to achieve this?

I know it's possible through style, but I can't use style.

Also I tried this example, but it doesn't work.

I have partially (some Tabs get new text size) succes with this:

try {
        Field tabTextSize = TabLayout.class.getDeclaredField("mTabTextSize");
        tabTextSize.setAccessible(true);
        tabTextSize.setFloat(mTabLayout, 64f);
    } catch (Exception e) {
        e.printStackTrace();
    }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
t.jancic
  • 190
  • 1
  • 3
  • 10

1 Answers1

4

try this

Create an xml layout named custom_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tab"
    android:textColor="@color/colorAccent"/>

than in your activity set text size programaticlly like below code

TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabOne.setText("ONE");
tabOne.setTextSize(14); // set font size as per your requirement 
tabLayout.getTabAt(0).setCustomView(tabOne);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163