[Nativescript][Android] Add badge on tabview tabs

android

#1

Can i add badge on tabview tabs?


#2

Here is an example how you can use badges in iOS and Android


#3

Thanks for solution.

is the project yours?


#4

Yes, I wrote that sample.


#5

very nice, thanks.

I made some changes to the code because I would like to see the badge as in the image I attached.
As you can see I eliminated the horizontal orientation and I set Y and X to place the badge.
The problem is that by adding the badge view at the bottom of the tabitem this creates space, how do you delete it?

07

can you help me?


#6

I’m not sure what exactly you updated, if you share the updated Playground example I can take a look.


#7

thanks.


#8

i tried use this library for add badge in android tabs
https://github.com/AlexLiuSheng/BadgeView

but look:

23


#9

I don’t see the exact example in Playground as you shown me in image, but still I think setting marginTop and marginRight to -30 will give you the desired output instead of setting X and Y.


#10

sorry i haven’t insert image for time.
Ok i solved with marginTop on the contenView.

Thanks :slight_smile:


#11

Hi alexma01,
you can not share your tabview with me?
Estou com o mesmo problema.


#12

Hi @andretimm.
I modified the project using the margin as I had been suggested.


#13

Great @alexma01,

It worked perfect .
I’m starting with nativescript now. And my problem now is, add badges after running my ngOnInit, not when the tab is loaded in the onTabViewLoaded event. Do you have any idea ?
And sorry my English, I’m Brazilian haha


#14

You can add / modify a component only when it’s created, ngOnInit doesn’t guarantee that the native components are created. May be you can try ngAfterViewInit.


#15

I’m sorry if I replied late.
Have you solved or do you still need help?


#16

@manojdcoder
Is this solution still working?
Couldn’t make it work

Thanks


UPD: nvm, resolved…


#17

Did you actually test it? The version I created still seems to work on my end.


#18

I tried to run playground on my iPhone and it failed, that is why I asked you.
Didn’t check on Android yet, but hope it works.

Using your code locally - no success on iOS.
item.bageValue is undefined

working solution for me on iOS:

if (isIOS) {
let tabItem = tabView.ios.tabBar.items[i]; // i - 0-based tabIndex
Preformatted text tabItem.badgeValue = “5”;
}


#19

Sorry, this thread was specific to Android, so I tested only in Android when you asked. iOS may need adjustments in 4.x, I will check and let you know.


#20

They have just renamed the internal variable from _iosViewController to __controller.

Updated my example.