How is TabItem used when placed in the layout XML?

This appears to be a relatively recent addition to the design library, apparently added in version 23.2.0, though it’s not mentioned in the revision history. It’s functionality is pretty basic, and the only attributes it seems to use are the three given in its docs: text, icon, and layout. From testing, it seems it’s basically … Read more

TabLayout with viewpager not smooth scrolling

I just went through your code. The problem is that you are not providing any layout to inflate inside ContentFragment.java. I changed your method to @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { //return super.onCreateView(inflater, container, savedInstanceState); return inflater.inflate(R.layout.feed_item, container, false); } After making these changes your tabs were scrolling … Read more

Cannot remove Padding from Tabs when using Custom views with Tab Layout

<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.

How to get current selected tab index in TabLayout?

Use OnTabSelectedListener. And then in this listener get the getPosition(). Something like this: tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){ @Override public void onTabSelected(TabLayout.Tab tab){ int position = tab.getPosition(); } }); UPDATE This method setOnTabSelectedListener() is deprecated . Use addOnTabSelectedListener(OnTabSelectedListener)