createTabBarItem reference:
window.uicontrols.createTabBarItem(name, label, image, options);
Name: Identity for manipulate on phonegap.
Label: Text with appear on tabbar
Images: Icon on tabbar
IPhone Default Images:
- tabButton:More
- tabButton:Favorites
- tabButton:Featured
- tabButton:TopRated
- tabButton:Recents
- tabButton:Contacts
- tabButton:History
- tabButton:Bookmarks
- tabButton:Search
- tabButton:Downloads
- tabButton:MostRecent
- tabButton:MostViewed
For others, insert your image in Project and use "image.png". For rules consult: http://developer.apple.com/iphone/library/documentation/userexperience/conceptual/mobilehig/IconsImages/IconsImages.html
Options:
onSelect: execute script on select tabBarItem.
Example: onSelect: function() { showTab('#otherView'); }
Phonegap 0.90 was used with this example.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" src="jquery.1.3.2.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).bind("deviceready", function() {
setupToolbars();
});
var toprated=0;
var recents=0;
var history=0;
function setupToolbars() {
window.uicontrols.createToolBar();
window.uicontrols.setToolBarTitle("A Title");
window.uicontrols.createTabBar();
var toprated = 0;
window.uicontrols.createTabBarItem("toprated", "Top Rated", "tabButton:TopRated", {
onSelect: function() {
navigator.notification.alert("Top Rated selected");
window.uicontrols.updateTabBarItem("toprated", { badge: ++toprated });
}
});
var recents = 0;
window.uicontrols.createTabBarItem("recents", "Recents", null, {
onSelect: function() {
navigator.notification.alert("Recents selected");
window.uicontrols.updateTabBarItem("recents", { badge: ++recents });
}
});
var history = 0;
window.uicontrols.createTabBarItem("history", "History", "icon.png", {
onSelect: function() {
navigator.notification.alert("History selected");
window.uicontrols.updateTabBarItem("history", { badge: ++history });
}
});
window.uicontrols.createTabBarItem("search", "Search", "tabButton:Search");
window.uicontrols.createTabBarItem("downloads", "Downloads", "tabButton:Downloads");
window.uicontrols.showTabBar();
window.uicontrols.showTabBarItems("toprated", "recents", "history");
}
</script>
</head>
<body id="stage" class="theme">
<div id="Page1">
<br><br><br>
<h1>The tab bar is kewl!</h1>
</div>
</body>
</html>
Comments (11)
Jesse MacFadyen said
at 4:11 pm on Dec 23, 2009
To remove the jQuery requirement, and still bind the deviceready event, you just need to call :
document.addEventListener("deviceready",setupToolbars);
Nice work!
laurent said
at 2:47 am on Feb 11, 2010
I can't find the phone gap 0.9.0
Could you give the files link to try your code?
Thanks in advance
Damian Montero said
at 7:10 am on Mar 10, 2010
For Phone Gap 0.9.0 go to the version of your phone in http://github.com/phonegap then click on the "download source" at the top right button.
For example, for the iphone it's: http://github.com/phonegap/phonegap-iphone
That's because 0.9.0 right now (as I write this) is the newest version.
Michael Stevens said
at 10:55 pm on Apr 16, 2010
If you remove the ToolBar the tabs push down below the bottom of the screen. Is there css or code to positions these elements?
Jordan said
at 2:38 pm on Apr 19, 2010
For those having problems with the TabBar being pushed down below the screen (this happens when the toolbar is NOT present). I used Samuels comment for the fix:
http://phonegap.lighthouseapp.com/projects/20116/tickets/24-uicontrols-edge-tabbar-with-wrong-size#ticket-24-16
It's a little hacky but it works for now.
Any ideas on how to get custom icons working? icon.png doesn't seem to show up. I've tried putting pngs in the "www" folder and just in the project folder.. no dice. Any suggestions would be extremely helpful.
Dustin Henderson said
at 5:18 pm on Apr 21, 2010
For all the web refugees like me... who are very new to this... To make the change above. You need find #yourprojectname#.xcodeproj (found in the root of your project). "right" click on that file and "open with finder". A new project should open in X-code. Expand plugins and open UIControls.m make above change. Click on build (menu item) and click build. Close this project and click build and go... you should be good to go!
KGiPhone said
at 1:30 pm on Apr 22, 2010
The code for the tool bar works great, but when I return to the page that I put the javascript, it adds another tabbar on top of the one that is already there. Can anyone help me out with this. Maybe I am putting the code in the wrong place?
RonaldK said
at 2:22 am on May 5, 2010
In my Phonegap version 0.9.0 UIcontrols.m was not in #yourprojectname#.xcodeproj but in PhoneGapLib.xcodeproj.
That's where I also found the files mentioned in http://groups.google.com/group/phonegap/msg/da20bf729378be30 . That fix fixes the huge blank area when in landscape mode.
NicolasG said
at 10:42 am on May 11, 2010
When I use this code the only thing I see is a white text "The tabBar is kwel" in the middle of the screen -_-
Techjunkie said
at 3:01 pm on Jun 3, 2010
NicolasG,
Just remove the line,
<script type="text/javascript" src="jquery.1.3.2.min.js"></script>
and replace lines
$(document).bind("deviceready", function() {
setupToolbars();
});
with
document.addEventListener("deviceready",setupToolbars);
Josiah Hester said
at 5:12 am on Jun 30, 2010
If you want to have a custom icon, you have todo a few things. First you have to make it either 30x30 or 60x60 (Hi-res), it has to have a transparent background and the shape is pure white. No drop shadow etc.. Then you have to specify the FULL path to the image, if my image is in the main www directory then I supply it like this:
window.uicontrols.createTabBarItem("random", "Random", "/www/random.png");
I attached a sample .png file that I used.
I
You don't have permission to comment on this page.