简体   繁体   中英

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

  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);

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM