Skip to content Skip to sidebar Skip to footer

TabLayout Set Text Size Of TabLayout.Tab From Code (programmatically)

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

Solution 1:

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);

Post a Comment for "TabLayout Set Text Size Of TabLayout.Tab From Code (programmatically)"