Search code examples
androidtabsmaterial-designandroid-tablayout

Getting the textview of the TabLayout's tab


I want to programmatically change a tab's textview. Is there any way to do this?

There are answers only concerning the old TabHost view, I am using the TabLayout used by Google's Material Design library using android.support.design.widget.TabLayout.

For TabHost: How to add padding to a tabs label?


Solution

  • With a given tab:

     int wantedTabIndex = 0;
     TextView tv = (TextView)(((LinearLayout)((LinearLayout)mTabLayout.getChildAt(0)).getChildAt(wantedTabIndex)).getChildAt(0));
     tv.setText("Hello world!");