类型 函数 库 native.* 返回值 无 修订版 2024.3703 版 关键字 提示、显示对象、原生对象 另请参见 native.showAlert()
以编程方式取消提示框。例如,你可能希望在十秒后即使用户未点击它也会自动消失的弹出提示。在这种情况下,可在计时器结束时调用此函数。
native.cancelAlert( alert )
表格. 要取消的提示,从 native.showAlert() 返回。
local function onComplete( event ) if event.action == "clicked" then local i = event.index if i == 1 then -- Do nothing; dialog will simply dismiss elseif i == 2 then -- Open URL if "Learn More" (the 2nd button) was clicked system.openURL( "https://solar2d.com/" ) end end end -- Show alert with two buttons local alert = native.showAlert( "Solar2D", "Dream. Build. Ship.", { "OK", "Learn More" }, onComplete ) -- Dismisses "alert" after 10 seconds if user has not responded local function cancelMyAlert() native.cancelAlert( alert ) end timer.performWithDelay( 10000, cancelMyAlert )
-- Handler that gets notified when the alert closes local function onComplete( event ) if event.action == "clicked" then local i = event.index if i == 1 then -- Do nothing; dialog will simply dismiss elseif i == 2 then -- Open URL if "Learn More" (second button) was clicked system.openURL( "https://solar2d.com/" ) end end end local alert if ( alert ~= nil ) then native.cancelAlert( alert ) alert = nil end local function showAlert() alert = native.showAlert( "Solar2D", "Dream. Build. Ship.", { "OK", "Learn More" }, onComplete ) end timer.performWithDelay( 10, showAlert )