apollow apollow - 1 year ago 76
Android Question

Getting the textview of the TabLayout's tab

I want to programmatically change a tab's textview programmatically. 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?

Answer Source

With a given tab:

 int wantedTabIndex = 0;
 TextView tv = (TextView)(((LinearLayout)((LinearLayout)mTabLayout.getChildAt(0)).getChildAt(wantedTabIndex)).getChildAt(0));
 tv.setText("Hello world!");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download