Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Tabbedbar badges like Facebook app, possible? (screenshot included)

I have a view that uses a tabbedbar

I am wanting to show badges on the tabbed bar. I have seen this on the FaceBook app like in the image below

FaceBook Example

Is this possible at all?

— asked November 22nd 2010 by Mark Beech
  • badges
  • facebook
  • tabbedbar
0 Comments

8 Answers

  • Accepted Answer

    I've made it quickly and it looks ugly, spend sometime on styling it.

    var ui = Ti.UI,
        win = ui.currentWindow;
    
    var label = ui.createLabel({
        text: "30",
        textAlign: "center",
        height: 25,
        width: 25,
        font: {
            fontWeight: "light",
            fontSize: 14
        },
        backgroundColor: "red",
        borderColor: "white",
        color: "white",
        borderRadius: 10,
        borderWidth: 3,
        top: -10,
        right: 5
    });
    
    var bar = ui.createTabbedBar({
        labels:["One","Two", "Three"],
        backgroundColor:'#336699",
        bottom:0,
        style:ui.iPhone.SystemButtonStyle.BAR,
        height:50
    });
    
    bar.add(label);
    win.add(bar);
    
    — answered November 23rd 2010 by mostafa farghaly
    permalink
    0 Comments
  • Im guessing that's a no then?

    — answered November 23rd 2010 by Mark Beech
    permalink
    0 Comments
  • Have you had a look at the KitchenSink examples? I know that they atleast included some badge stuff in the dashboard view example.

    View here: https://github.com/appcelerator/KitchenSink/blob/master/KitchenSink/Resources/examples/dashboard.js

    Hope that helps.

    — answered November 23rd 2010 by Fredrik Nordlund
    permalink
    1 Comment
    • Hi, thanks for the response

      Ive been right through the kitchen sink and can't see anything that sets badges on tabbed bars

      I am using the dashboard view in my app and have that pretty much sussed, it is just i cant seem to add badges to a tabbed bar

      — commented November 23rd 2010 by Mark Beech
  • if you can't add badge to the individual buttons from Ti API, it's trivial to code this functionality:

    1- the badge is red gradiet label with say 2px border and say 5px border radius and text color white
    2- the button right hand side equals to (tabbedbar width / buttons number) - badge width
    3- hide and show the badge when needed

    btw i didn't do this before, but if i have to i'll :)

    — answered November 23rd 2010 by mostafa farghaly
    permalink
    3 Comments
    • Hi, thank you for your reply. I have tried creating a view and adding it to the tabbed bar but it didn't seem to work. Should it be possible to add a view to a tabbed bar?

      — commented November 23rd 2010 by Mark Beech
    • yes, there's .add() method for TabbedBar, as far as i know all UI widgets inherit from [TiUIView] and can be added to each other, let me know the result when done. try increasing the zIndex, it maybe shown but below - who knows, try different approaches.

      — commented November 23rd 2010 by mostafa farghaly
    • hmmm….i have just tried it. When i create a label, then add it to my tabbedbar, my application creashes with this error

      [ERROR] The application has crashed with an unhandled exception. Stack trace:…..

      — commented November 23rd 2010 by Mark Beech
  • Sorry if i gave you false information.

    I havent had time to actually try this myself but iam positive it should be possible to use badges on tabbars and buttons..

    Third time is the charm?

    In Kitchen Sink look at:
    Base UI > Tabs > Toggle Tab Badge

    Quick look at the code here:
    https://github.com/appcelerator/KitchenSink/blob/master/KitchenSink/Resources/examples/tabs.js

    — answered November 23rd 2010 by Fredrik Nordlund
    permalink
    1 Comment
    • if you look through that code, you will see the "only" place badges are being assigned is to Tabs… Not buttons… unless I am missing something

      — commented November 23rd 2010 by Aaron Saunders
  • i'm running against the same problem, tried numerous things but w/o anly luck.

    — answered November 29th 2010 by Glenn Tillemans
    permalink
    0 Comments
  • just create the badge view using a regular Ti.UI.View, and add it to the window with a higher zIndex… them you need to position it properly over the tabbed bar (shouldn't be hard, just get the width and divide it properly by the number of buttons inside the bar for horizontal positioning).

    — answered August 25th 2012 by Ygor Lemos
    permalink
    0 Comments
  • If you run Kitchen Sink you will see that there is a badge in the dashboard view example.

    If you check the code out: https://github.com/appcelerator/KitchenSink/blob/master/KitchenSink/Resources/examples/dashboard.js

    You will see that there is a code snippet for the badge, something like this:

    var item = Titanium.UI.createDashboardItem({
    image:'image.png',
    selectedImage:'selectedimage.png',
    label:'label text',
    badge:10
    });
    data.push(item);
    
    var dashboard = Titanium.UI.createDashboardView();
    win.add(dashboard);
    

    That is not the complete code but notice the "badge:10" thingy…

    — answered November 23rd 2010 by Fredrik Nordlund
    permalink
    2 Comments
    • doesnt work on buttons

      — commented November 23rd 2010 by Aaron Saunders
    • Thanks again for your response. I have the dashboard covered, not a problem. Im talking about a tabbed bar (like in the screenshot), not a dashboard item

      — commented November 23rd 2010 by Mark Beech
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.