MrMR
MrMR

Reputation: 279

How to add Badge to Android tablayout

I want to add badge to my TabLayout. When each add new element (item ListView) in database I want to show a Badge ( +1 ) in order to inform the user about each new.

Like this image :

Any help would be appreciated

Upvotes: 1

Views: 4429

Answers (2)

Ferdous Ahamed
Ferdous Ahamed

Reputation: 21766

  1. Design a custom view for each TAB.
  2. Set custom view to each TAB by using TAB.setCustomView(custom_View)

Try this:

    // Tab
    Tab tab = YourTabLayout.getTabAt(position);

    // Get Custom view using LayoutInflater
    // ...........

    // Set custom view
    tab.setCustomView(custom_View);

Upvotes: 3

Matthew Shearer
Matthew Shearer

Reputation: 2795

You will need to add a custom View to each tab. so once you have your ViewPager and Adapter all set up.

Iterate over the tabs and add custom views.

something like:

for (int i = 0; i < tabLayout.getTabCount(); i++) {
    TabLayout.Tab tab = tabLayout.getTabAt(i);
    tab.setCustomView(createCustomViewForTab(i);
}

Upvotes: 0

Related Questions