disable tab
Hi
I would like to disable a tab or at least popup a message saying that you should do a login before using that specific tab.
I have used setActiveTab to enable the login tab, I had some problem sinche the login tab was on the 5th position.
Someone can help me out, in order to disable and put some opacity on specific tabs.
Thank you
6 Answers
-
Disclaimer: this is a hack.
I haven't tried this with Andriod but this worked with iPhone. There is definitely a way to do this with the iPhone SDK http://forums.macrumors.com/showthread.php?t=615581. Since it doesn't seem like this feature is exposed though, I'm just adding a transparent image over the tab bar until the user logs in, then I call the
disableNonSettingsTabs
function on the tabGroup object to remove the image.var disableTabsImage = Titanium.UI.createView({ backgroundImage:'transparent.png', height:50, width:'100%', bottom:0, left:0 }); tabGroup.add(disableTabsImage); tabGroup.enableNonSettingsTabs = function(){ this.remove(disableTabsImage); }; tabGroup.disableNonSettingsTabs = function(){ tabGroup.setActiveTab(settingsTab); this.add(disableTabsImage); }; var loginAlert = Titanium.UI.createAlertDialog({ title:'Please login', message:'Please login first.' }); disableTabsImage.addEventListener('click', function(e){ loginAlert.show(); });
-
Have you found the answer? or does anyone? Having the same question here!
-
bump. Same problem as well.
-
I have the same problem too…
-
Prevent Tab Switching on Condition
One way to prevent tab changing is to set the active tab to the tab you were just on when a condition is met. As you can see, it's not very clean:
var change = true; tabGroup.addEventListener('blur',function(e){ if (lockTabs && change) { if (e.previousIndex!=e.index) { tabGroup.setActiveTab(e.previousIndex); change = false; } } else if (change===false) { change = true; } });
Explanation: Essentially what it does is switch the tab on the blur event only when:
- the given condition is met, in this case the
lockTabs
variable (line 3) - the event isn't being fired because we are changing the tab (line 3)
- the tab clicked is not the tab we were just at (line 4)
It's kind of confusing, but if you take out the
change
variable you'll notice that it switches from the active tab to the previous tab in an infinite loop. You have to let theblur
event at least fire once freely. - the given condition is met, in this case the
-
I was googling for lock or disable tab, and found this thread.
I ended up going with:
tab1.touchEnabled =false
or you can also lock the whole tabgroup which is what I wanted awaiting xhr callback
tabGroup.touchEnabled = false
My first post! enjoy..