Skip to content

Instantly share code, notes, and snippets.

@sunwicked
Created October 21, 2015 11:10
Show Gist options
  • Save sunwicked/1f56693b9bcb2084d21a to your computer and use it in GitHub Desktop.
Save sunwicked/1f56693b9bcb2084d21a to your computer and use it in GitHub Desktop.
Creating Custom Tabs to add divider
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
RelativeLayout relativeLayout = (RelativeLayout)
LayoutInflater.from(this).inflate(R.layout.tab_layout, tabLayout, false);
TextView tabTextView = (TextView) relativeLayout.findViewById(R.id.tab_title);
tabTextView.setText(tab.getText());
tab.setCustomView(relativeLayout);
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Tab title -->
<TextView
android:id="@+id/tab_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
/>
<!-- Tab divider -->
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="@android:color/white" />
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment