I want to implement notification badge with android.support.design.widget.TabLayout
. I had tried my best effort to implement it but fails.
Any help would by greatly appreciated.
I want to implement notification badge with android.support.design.widget.TabLayout
. I had tried my best effort to implement it but fails.
Any help would by greatly appreciated.
My solution to this was using https://github.com/jgilfelt/android-viewbadger and setting a custom view to each tab:
My tabs have only icons so I used ImageView, but I believe you can use any other view, check https://github.com/jgilfelt/android-viewbadger/blob/master/README.markdown:
just use this trick :
I don' know why but none of the above answers worked for me :(
I have my own Solution that is gonna make the same tablayout as the whatsapp with that badge :)
First make a custom tab Layout as custom_tab
Second a badge_background
Third a tab_color_selector
Fourth in your activity
Fifth Define setupTabIcons and prepareTabView methods
I might have left something during answering this question, Just ping me, I would be happy to help :D
I would suggest you look at this website:
https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout#design-support-library
You can iterate through the different tabs using this method and set the custom views to whatever you want:
There are easy way as well. Just append a special characters behind. It will look like whatsapp does.
➀ ➁ ➂ ➃ ➄ ➅ ➆ ➇ ➈ ➉ ➊ ➋ ➌ ➍ ➎ ➏ ➐ ➑ ➒ ➓
I tried some of the above mentioned solutions, but they did not deliver proper results. If you take a closer look in the
TabLayout
implementation you will realize that theTabView
will try to get the textView and iconView from theCustomView
if applied.So instead of doing some hacky implementations I rather came up with a layout equal to the one from the original
TabView
but an additional view which can have a badge.So you will need the badged_tab.xml layout
And some sort of notification background:
When adding your tab programatically just call
And then you can show / hide / set a badge cound at any time via: