GitPedia

TabDrawer

Android Navigation Tab Bar with Drawer - Alternative to Navigation Drawer (Hamburger Menu)

From ashazar·Updated March 8, 2025·View on GitHub·
·Archived

Android Navigation Tab Bar with Drawer - Alternative to Navigation Drawer *(Hamburger Menu)* The project is written primarily in Java, distributed under the MIT License license, first published in 2016. Key topics include: android, android-navigation-tab, drawer, hamburger-menu, navigation-drawer.

Latest release: 1.1.0Customize Tabs and Drawers as You Want
February 5, 2017View Changelog →

TabDrawer

Android Navigation Tab Bar with Drawer - Alternative to Navigation Drawer (Hamburger Menu)

DemoDemo_TabBarDemo_Custom_TabDrawer
DemoStandard Tab BarCustom Layouts

TabDrawer is an Open Source library for Android apps; combining the Navigation Tab Bar and a much user-friendly alternative to Navigation Drawer (Hamburger Menu)

You can easily add a fully customized Navigation Tab Bar (Bottom/Top/Left/Right), and a drawer for each tab that contains lists for navigating to different sections of the app.


v. 1.2.0 Release Notes:

  • Badges added for Tabs
  • Add below sample in your layout's TabDrawerLayout section
       tab:badgePosition="topRight"
       tab:badgeMarginToTabCorner="2dp"
       tab:badgePadding="2dp"
       tab:badgeColor="#ff0000"
       tab:badgeTextColor="#ffffff"
       tab:badgeSize="14dp"
       tab:badgeTextSize="10sp"
  • .setBadgeCount(int tabPosition, int count)
  • .getBadgeCount(int tabPosition)
  • .clearBadgeCount(int tabPosition)
  • Manually trigger Tab selection via .setSelectedTab(int tabPosition, int itemPosition, boolean sendClickInfo)

Adding TabDrawer Library

Gradle (through JCenter)

Simply add compile 'com.ashazar.tabdrawer:tabdrawer:1.2.0' in dependencies in your app's build.gradle file

dependencies {
    compile 'com.ashazar.tabdrawer:tabdrawer:1.2.0'
}

Using TabDrawer

Layout
  • Set your root layout as RelativeLayout.
  • Add xmlns:tab="http://schemas.android.com/apk/res-auto" namespace definition in RelativeLayout, in order to use TabDrawerLayout's own attributes.
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tab="http://schemas.android.com/apk/res-auto"
    ...
  • Place TabDrawerLayout as last child of root RelativeLayout. (Attribute explanations table for TabDrawerLayout is below the instructions)
    <com.ashazar.tabdrawer.TabDrawerLayout
        android:id="@+id/tabDrawer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        tab:tabBarPosition="bottom"
        tab:size_tabBar="48dp"
        tab:size_Total="240dp"
        tab:defaultSelectedTab="1"
        tab:padding="3dp"
        tab:drawer_padding="2dp"
        tab:list_padding="10dp"
        
        tab:badgePosition="topRight"
        tab:badgeMarginToTabCorner="2dp"
        tab:badgePadding="2dp"
        tab:badgeColor="#ff0000"
        tab:badgeTextColor="#ffffff"
        tab:badgeSize="14dp"
        tab:badgeTextSize="10sp"
        />
In Your Code
  • Prepare TabDrawerData, object that holds all Tabs and Tabs' list items, as well as their properties (color, background color, etc.).
    (Method explanations table for TabDrawerData, Tab and TabListItem is below the instructions)

  • Tabs can be: (a) Icon only, (b) Text only, or (c) Icon and Text (as in the sample app.)

  • Tabs can: (a) have item lists (TabListItem), or (b) Tab only (act as a normal tab in a standard Tab Bar; no drawer opens, will be selected immediately, when clicked)

  • Tab list items can be: (a) Text only, (b) Icon and Text (as in the sample app.), or (c) Icon only.

TabDrawerData tabDrawerData = new TabDrawerData()
                .setTabIconColors(
                        Color.parseColor("#3199ff"),
                        Color.parseColor("#ffffff")
                )
                .setTabTitleSize(12)
                .setTabTitleColors(
                        ContextCompat.getColor(context, R.color.tabTitle),
                        ContextCompat.getColor(context, R.color.tabTitle_selected),
                        Color.parseColor("#CCCCCC")
                )
                .setTabBackgroundColors(
                        ContextCompat.getColor(context, R.color.tabBackground),
                        ContextCompat.getColor(context, R.color.tabBackground_selected)
                )
                .setTabListItemTitleColors(Color.parseColor("#ffffff"))
                .setTabListItemTitleSize(16)

                .addTab( new Tab()
                        .setTitle("Demo")
                )

                .addTab( new Tab()
                        .setTitle("Queue")
                        .setIconImage(R.drawable.n_queue)
                        .setDrawerListColumnNumber(2)
                        .addTabListItem( new TabListItem("Add to Queue", R.drawable.ic_add_box_white_24dp ) )
                        .addTabListItem( new TabListItem("Archive", R.drawable.ic_archive_white_24dp) )
                );

  • Prepare TabDrawer and Initialize
  • TabDrawer takes following arguments: Context, Activity, TabDrawerLayout's Id, and TabDrawerData
  • You need to override onTabDrawerClicked() to get clicked Tab's and item's positions.
  • onTabDrawerClicked() only passes the clicks you need. So you don't have to do checks for open/close drawer; or whether the Tab or item already selected.
  • Call initialize()
TabDrawer tabDrawer = new TabDrawer(context, activity, R.id.tabDrawer, tabArray) {
            @Override
            public void onTabDrawerClicked(int tabPosition, int itemPosition) {
                super.onTabDrawerClicked(tabPosition, itemPosition);
            }
        };

        tabDrawer.initialize();

If you want more customization, you can override below methods to modify the views as you want.
For Tabs:

  • setUnselectedTabView(RelativeLayout tabLayout, ImageView iconView, TextView titleView, int tabPosition)
  • setSelectedTabView(RelativeLayout tabLayout, ImageView iconView, TextView titleView, int tabPosition)
  • setInactiveSelectedTabView(RelativeLayout tabLayout, ImageView iconView, TextView titleView, int tabPosition)

For List Items in Drawer:

  • setUnselectedListItemView(int tabPosition, int itemPosition, View view, ImageView iconView, TextView titleView)
  • setSelectedListItemView(int tabPosition, int itemPosition, View view, ImageView iconView, TextView titleView)

You can override onBackPressed() to close Drawer when pressed 'Back'.

@Override
public void onBackPressed() {
    if (tabDrawer.isDrawerOpen())
        tabDrawer.closeDrawer();
    else
        super.onBackPressed();
}

Attributes for TabDrawerLayout
AttributeMandatoryExplanation
NameSpace: android
layout_widthyes"match_parent" for Top/Bottom TabDrawer; "wrap_content" for Left/Right TabDrawer
layout_heightyes"wrap_content" for Top/Bottom TabDrawer; "match_parent" for Left/Right TabDrawer
NameSpace: tab
topBarPositionyestop / bottom / left / right
size_tabBaryesSize (in 'dp') of the TabBar only.
Height for Top / Bottom TabDrawer; Width for Left / Right TabDrawer
size_TotalyesSize (in 'dp') of the TabBar & Drawer (when opened)
Height for Top / Bottom TabDrawer; Width for Left / Right TabDrawer
defaultSelectedTabnoInitial highlighted Tab number. (default: 1) (integer)
1 for first Tab. (not 0)
paddingnoPadding of the Tab itself. (in 'dp')
Can also use paddingTop, paddingBottom, paddingLeft, paddingRight
drawer_paddingnoPadding for the Drawer (in 'dp')
Can also use list_paddingTop, list_paddingBottom, list_paddingLeft, list_paddingRight
list_paddingnoPadding for the Drawer's GridView (in 'dp')
Can also use list_paddingTop, list_paddingBottom, list_paddingLeft, list_paddingRight
badgePositionyesPosition of the badges
topRight, topLeft, bottomRight, bottomLeft, center
badgeMarginToTabCornernoMargin from the corners (in 'dp')
Example: For topRight badge; it uses marginTop and marginRight
badgePaddingnoInner padding of the badge (in 'dp')
badgeColornoBackground color of the badge
badgeTextColornoText color of the badge
badgeTextSizeyesText size (in 'sp')
Methods for TabDrawerData, Tab, TabListItem
MethodExplanationArgument Type
TabDrawerDataOBJECT
.setTabBackgroundColors()Sets the background colors of all Tabs (default, selected, inactiveSelected)int (,int) (,int)
.setTabTitleColors()Sets title colors of all Tabs (default, selected, inactiveSelected)int (,int) (,int)
.setTabTitleSize()Sets title size for all Tabsint (sp)
.setTabTitleFont()Sets Typeface of the title for all TabsTypeFace
.setTabIconColors()Sets tab icon colors of all Tabs (default, selected, inactiveSelected)int (,int) (,int)
.setAnimateScaleTabIconWhenSelected()Sets if to animate and scale up the icon, when tab is selected (default: true)boolean
.setTabIconScaleValueWhenSelected()Sets the scale value of selected tab's icon. (default: 1.2f)float
.setBoldTabTitleWhenSelected()Sets if to make the title bold, when tab is selected (default: true)boolean
.setCustomTabLayoutResourceId()Sets the Custom Layout Resource Id of all tabsint
.dontUseDefaultTabViewSettings()Sets if the developer wants to reset and override the default Tab view settingsvoid
below methods are for drawer and lists
.setCustomDrawerLayoutResourceId()Sets the custom drawer layout (RelativeLayout) resource Id for all tabsint
.setDrawerListColumnNumber()Sets the number of columns in GridView in the drawer (default: 1)int
.setCustomDrawerGridViewId()Sets the id for the custom GridView inside the custom drawer layoutint
.setCustomDrawerListItemLayoutResourceId()Sets the resource id for the custom item layout for GridView inside the drawerint
.setTabListItemTitleColors()Sets tab list item's title color of all Tabs (default, selected)int (,int)
.setTabListItemTitleSize()Sets tab item list text sizeint (sp)
.setTabListItemTitleFont()Sets Typeface of the Tab List item's TitleTypeFace
.dontUseDefaultTabListAdapterViewSettings()Sets if the developer wants to reset and override the default List item view settingsvoid
.addTab()Add a new TabTab
TabOBJECT
.setTitle()Set Tab's title textString
.setIconImage()Set Tab's icons (drawableIds) (default, selected, inactiveSelected)int (,int) (,int)
.setCustomTabLayoutResourceId()Sets the Custom Layout Resource Id of tabint
.forceDefaultLayout()Force using default layout, if a custom layout set in TabDrawerDatavoid
.setBackgroundColors()Sets the background colors of the tab (default, selected, inactiveSelected)int (,int) (,int)
.setTabTitleColors()Sets title colors of the Tab (default, selected, inactiveSelected)int (,int) (,int)
.setTitleSize()Sets title size of the tabint (sp)
.setTitleFont()Sets Typeface of the title of the tabTypeFace
.setIconColors()Sets tab icon colors of the Tab (default, selected, inactiveSelected)int (,int) (,int)
.setAnimateScaleIconWhenSelected()Sets if to animate and scale up the icon, when tab is selected (default: true)boolean
.setIconScaleValueWhenSelected()Sets the scale value of selected tab's icon. (default: 1.2f)float
.setBoldTitleWhenSelected()Sets if to make the title bold, when tab is selected (default: true)boolean
.dontUseDefaultTabViewSettings()Sets if the developer wants to reset and override the default Tab view settingsvoid
below methods are for drawer and lists
.addTabListItem()Add list item to that tab's drawervoid
.setCustomDrawerLayoutResourceId()Sets the custom drawer layout (RelativeLayout) resource Id for the tabint
.setDrawerListColumnNumber()Sets the number of columns in GridView in the drawer (default: 1)int
.setCustomDrawerGridViewId()Sets the id for the custom GridView inside the custom drawer layoutint
.setCustomDrawerListItemLayoutResourceId()Sets the resource id for the custom item layout for GridView inside the drawerint
.forceDefaultDrawerLayout()Force using default drawer layout, if a custom layout set in TabDrawerDatavoid
.setListItemTitleColors()Sets tab list item's title colors (default, selected, inactiveSelected)int (,int)
.setListItemTitleSize()Sets tab item list text size.int (sp)
.setListItemTitleFont()Sets Typeface of the List item's TitleTypeFace
.dontUseDefaultListAdapterViewSettings()Sets if the developer wants to reset and override the default List item view settingsvoid
TabListItemOBJECT
Instantiates with
TabListItem(Title), TabListItem(Icon) or TabListItem(Title, Icon)

TabDrawer idea inspired by Scott Jensen's article Designing an Alternative to the Hamburger Menu

License

MIT License

Copyright (c) 2016 Serdar Hazar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Contributors

Showing top 1 contributor by commit count.

View all contributors on GitHub →

This article is auto-generated from ashazar/TabDrawer via the GitHub API.Last fetched: 6/21/2026