It’s almost the same as in the example, except without the highlighter images.
[lua]
local widget = require( “widget” )
– Function to handle button events
local function handleTabBarEvent( event )
print( event.target._id )
end
– Configure the tab buttons to appear within the bar
local tabButtons = {
{
width = 72,
height = 120,
defaultFile = “tabBarIconDef.png”,
overFile = “tabBarIconOver.png”,
label = “Tab1”,
id = “tab1”,
selected = true,
size = 16,
labelYOffset = -8,
onPress = handleTabBarEvent
},
{
width = 72,
height = 120,
defaultFile = “tabBarIconDef.png”,
overFile = “tabBarIconOver.png”,
label = “Tab2”,
id = “tab2”,
size = 16,
labelYOffset = -8,
onPress = handleTabBarEvent
},
{
width = 72,
height = 120,
defaultFile = “tabBarIconDef.png”,
overFile = “tabBarIconOver.png”,
label = “Tab3”,
id = “tab3”,
size = 16,
labelYOffset = -8,
onPress = handleTabBarEvent
}
}
– Create the widget
local tabBar = widget.newTabBar {
left = 0,
top = display.contentHeight-120,
width = 580,
height = 120,
backgroundFile = “tabBarBack.png”,
buttons = tabButtons
}
[/lua]
And here’s the code that works.
[lua]
local widget = require( “widget” )
– Function to handle button events
local function handleTabBarEvent( event )
print( event.target._id )
end
– Configure the tab buttons to appear within the bar
local tabButtons = {
{
width = 72,
height = 120,
label = “Tab1”,
id = “tab1”,
selected = true,
size = 16,
labelYOffset = -8,
onPress = handleTabBarEvent
},
{
width = 72,
height = 120,
label = “Tab2”,
id = “tab2”,
size = 16,
labelYOffset = -8,
onPress = handleTabBarEvent
},
{
width = 72,
height = 120,
defaultFile = “tabBarIconDef.png”,
overFile = “tabBarIconOver.png”,
label = “Tab3”,
id = “tab3”,
size = 16,
labelYOffset = -8,
onPress = handleTabBarEvent
}
}
– Create the widget
local tabBar = widget.newTabBar {
left = 0,
top = display.contentHeight-120,
width = 580,
height = 120,
buttons = tabButtons
}
[/lua]
I have no idea how to make this work. I was going to use it for a menu design with the bar on the top and the actual menu on the bottom. But i decided that it would be better to just use regular buttons arranged all over the screen(since i get to put a picture/animation in there to represent the sub-menu).
But still if you could explain it that would be great(It would be useful later).