Well, after 2-3 hours of work, I finally found a solution.
If you use TabLayout, there is no way to add fields to tabs using styles, etc. (like @Connecting life with Android earlier)
But you can do this by writing Java code. In general, your code should look something like this:
for(int i=0; i < mTabLayout.getTabCount(); i++) { View tab = ((ViewGroup) mTabLayout.getChildAt(0)).getChildAt(i); ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) tab.getLayoutParams(); p.setMargins(0, 0, 50, 0); tab.requestLayout(); }
To get each tab as a view, we must first get the container that contains them. In this case, TabLayout uses SlidingTabStrip as a container for tabs. SlidingTabStrip is the first child of TabLayout:
View tab = ((ViewGroup) mTabLayout.getChildAt(0))
And after this small detail, everything is pretty straightforward.
Todor Kostov Apr 11 '16 at 15:00 2016-04-11 15:00
source share