Created
April 21, 2012 03:50
-
-
Save minhnc/2433754 to your computer and use it in GitHub Desktop.
Navigation & TabGroup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rootWindow = Titanium.UI.createWindow({backgroundColor : "white", title : "Login"}); | |
var loginBtn = Ti.UI.createButton({title: 'Login', width: 100, height: 40}); | |
rootWindow.add(loginBtn); | |
var nav = Titanium.UI.iPhone.createNavigationGroup({ | |
window : rootWindow | |
}); | |
var win = Titanium.UI.createWindow(); | |
win.add(nav); | |
win.open(); | |
loginBtn.addEventListener('click', function(){ | |
var detailWin = Titanium.UI.createWindow({backgroundColor : "white", title : "Home"}); | |
var storeBtn = Ti.UI.createButton({title: 'Store', width: 100, height: 40, top: 20, _id: 'store'}); | |
var blogBtn = Ti.UI.createButton({title: 'Blog', width: 100, height: 40, top: 70, _id: 'blog'}); | |
detailWin.add(storeBtn); | |
detailWin.add(blogBtn); | |
nav.open(detailWin, {animated : true}); | |
storeBtn.addEventListener('click', openTabGroup); | |
blogBtn.addEventListener('click', openTabGroup); | |
}); | |
function openTabGroup(e) { | |
var tg = Ti.UI.createTabGroup(); | |
if ( e.source._id == 'store' ) { | |
var t1 = Ti.UI.createTab({title: 'Tab 1', window: Ti.UI.createWindow({backgroundColor: 'blue'})}); | |
var t2 = Ti.UI.createTab({title: 'Tab 2', window: Ti.UI.createWindow({backgroundColor: 'green'})}); | |
tg.addTab(t1); | |
tg.addTab(t2); | |
} else { | |
var t1 = Ti.UI.createTab({title: 'Tab 1', window: Ti.UI.createWindow({backgroundColor: 'black'})}); | |
var t2 = Ti.UI.createTab({title: 'Tab 2', window: Ti.UI.createWindow({backgroundColor: 'white'})}); | |
var t3 = Ti.UI.createTab({title: 'Tab 3', window: Ti.UI.createWindow({backgroundColor: 'brown'})}); | |
tg.addTab(t1); | |
tg.addTab(t2); | |
tg.addTab(t3); | |
} | |
// Setting Window with Logout button | |
var settingWin = Ti.UI.createWindow({backgroundColor: 'white'}); | |
var logoutBtn = Ti.UI.createButton({title: 'Return to Home', width: 200, height: 40}); | |
settingWin.add(logoutBtn); | |
var settingTab = Ti.UI.createTab({title: 'Setting', window: settingWin}); | |
tg.addTab(settingTab); | |
tg.open(); | |
logoutBtn.addEventListener('click', function(){ | |
tg.close(); | |
tg = null; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment