I have added a Relative Layout in Custom View and have added this in Tab Layout. I am using a white background for tabs and have not applied any padding in tabs custom layou
Through XML you can remove only the left and right paddings like that:
app:tabPaddingEnd="0dp"
app:tabPaddingStart="0dp"
Notice, that this way doesn`t work for TOP and BOTTOM paddings, but I find next solution:
When you use custom views as tab item, you need to set LayoutParams to the view and set paddings 0.
for (int i = 0; i < tabLayout.getTabCount(); i++) {
View tabView = LayoutInflater.from(context)
.inflate(LayoutInflater.from(this), R.layout.item_main_tabview, null, false);
tabView.setLayoutParams(new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
tabView.setPadding(0, 0, 0, 0);
tabLayout.getTabAt(i).setCustomView(tabViewBinding.getRoot());
}
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="210dp"
android:layout_height="28dp"
android:layout_centerInParent="true"
android:background="@drawable/bg_forum_tab"
app:tabIndicatorColor="@color/colorBtnBg"
app:tabIndicatorHeight="0dp"
app:tabPaddingBottom="-1dp"
app:tabPaddingEnd="-1dp"
app:tabPaddingStart="-1dp"
app:tabPaddingTop="-1dp"
app:tabSelectedTextColor="@color/colorBtnBg"
app:tabTextColor="@color/colorWhite" />
Set tabPaddingStart
/tabPaddingEnd
/tabPaddingTop
/tabPaddingBottom
like this.