Use TabLayout for this.
XML:
<android.support.design.widget.TabLayout android:id="@+id/tabLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:minHeight="100dp" app:tabGravity="fill" app:tabMode="fixed" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
code:
tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab()); View custom = LayoutInflater.from(this).inflate(R.layout.custom_tab, null); ((TextView) custom.findViewById(R.id.tabTitle)).setText("Tab 3"); (custom.findViewById(R.id.tabIcon)).setBackgroundResource(R.drawable.ic_place_white_18dp); TabLayout.Tab customTab = tabLayout.getTabAt(2); customTab.setCustomView(custom); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { switch (tabLayout.getSelectedTabPosition()) { case 0: //do what you want when tab 0 is selected break; case 1: //do what you want when tab 1 is selected break; case 2: //do what you want when tab 2 is selected break; default: break; } } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } });
EDIT:
The third tab uses a custom layout.
source share