Android TabLayout tabPaddingTop and tabPaddingBottom not being removed
Please refer to the above issue as well.
Even since i updated my design library to \"23.2.
I was stuck for hours until I found the method tab.setCustomView(idRes)
. Changing from inflated to this worked for me. Alernatively, if you are inflating you can use TabLayout.TabView
as root viewgroup.
Apart from this, I am not sure if it is helpful but I used minWidth
to the custom view layout.
This is what I wanted
In my case the problem was giving fixed height to the custom layout that i use for tabs.
Using match_parent
fixed my issue.
Just pass your tabLayout to this method and it's done!
private void setTabLayoutMatchParent(TabLayout tabLayout) {
final ViewGroup tabLayoutChild = (ViewGroup)(tabLayout.getChildAt(0));
int tabLen = tabLayoutChild.getChildCount();
for (int j = 0; j < tabLen; j++) {
View v = tabLayoutChild.getChildAt(j);
v.setPadding(0, 0, 0, 0);
}
}
Instead of dealing with TabLayout
subviews, you can access TabLayout.Tab
view directly and set the padding to 0
just like the code below.
for (int i = 0; i < tabLayout.getTabCount(); i++) {
View tabView = tabLayout.getTabAt(i).view;
tabView.setPadding(0, 0, 0, 0);
}
I'm doing this in the onCreateView
callback and it works perfectly.
Try adding below attributes to TabLayout:
app:tabPaddingStart="-1dp"
app:tabPaddingEnd="-1dp"
Hope it'll work.
Setting different values or layout params did not work, so the only solution I got was to add the following, after you add the tabs to your tab layout,
final ViewGroup test = (ViewGroup)(tabs.getChildAt(0));//tabs is your Tablayout
int tabLen = test.getChildCount();
for (int i = 0; i < tabLen; i++) {
View v = test.getChildAt(i);
v.setPadding(0, 0, 0, 0);
}