object:setSelected()

类型 功能
widget.*
返回值
修订版 2024.3703 版
关键词 widget、tab 栏、TabBarWidget、setSelected
另请参见 widget.newTabBar()
TabBarWidget

概述

使用此方法将特定的 TabBarWidget 按钮设为其“已选择”状态。您也可以同时调用按钮的 onPress 侦听器。

语法

object:setSelected( buttonIndex )
object:setSelected( buttonIndex, simulatePress )
buttonIndex (必需)

Number选项卡栏上的按钮索引,从 1 开始,表示最左侧的第一个按钮。

simulatePress (可选)

Boolean如果设为 true,则由 buttonIndex 指定的选项卡按钮将调用其 onPress 侦听器函数。默认值为 false,这意味着选项卡按钮将显示为“已选择”状态,但不会调用侦听器函数。

示例

-- Select the third tab
tabBar:setSelected( 3 )  

-- Select the second tab button and invoke its listener function
tabBar:setSelected( 2, true )