focus - 使用 Brightscript 使用两个文本框和按钮保持焦点
问题描述
我在明亮的脚本中创建了一个登录表单。它在跟随
''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''
TextBox 1 ' 这里的焦点是活动的 我在 TextBox 字段中默认设置 active = true
TextBox 2 ' 这里按下键激活 true
Button 1 ' 这里再次按下键聚焦 true
''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''
在这里,我使用 3 个不同的键来维护 3 个项目。现在我想使用向下键维护所有 3 个项目的单个键。任何人都知道如何使用 Brightscript 保持焦点。
我使用了一个功能来处理密钥它在这里
function onKeyEvent(key as String, press as Boolean) as Boolean
.................
end function
现在,我维护了密钥,就像我在默认设置中将文本框焦点设置为 XML 文件一样。现在我将逻辑应用到下面。默认情况下,第一项焦点设置在 XML 文件上。
if key = "down" then
'Here Second item focus
m.keypass.active = true ' Here work successfully First time
if key = "down" and m.keypass.active = true and m.btnsub.active = false then
'Here not maintain successfully its directly call here I press the down key.
m.keypass.active = false
m.btnsub.active = true 'Here third item focus is not maintained
end if
end if
我第一次按下向下键它工作正常但第二次如何处理焦点。我在向上键中使用了同样的东西。
在这里我使用“and”然后问题会发生是否有任何想法。
编辑帖子:
我用下面的代码处理上下键。它正在工作但是,它只能在一次内工作。
if key = "up" or key = "down"
if key = "down"
?"here down key"
if m.keypass.id = "instructpass" and m.keypass.active = true
? "down key if part"
m.btngrp.setFocus(true)
m.keypass.active = false
handled = true
else if m.keyid.id = "instructid" and m.keyid.active = true
?" down key else part"
m.keypass.active = true
m.keyid.active = false
handled = true
else if m.btngrp.buttonSelected = 0
m.keyid.active = true
m.btngrp.setFocus(false)
handled = true
end if
handled = true
else if key = "up"
? "here up key"
if m.keypass.active = true
?"up key if part"
m.keyid.active = true
m.keypass.active = false
handled = true
else if m.keyid.active = true
?"id key"
m.btngrp.setFocus(true)
m.btngrp.focusButton = 1
m.keyid.active = false
handled = true
else if m.btngrp.focusButton = 0 and m.btngrp.buttonSelected = 0
?"up key else part"
m.keypass.active = true
m.keypass.setFocus(true)
m.btngrp.setFocus(false)
handled = true
end if
handled = true
end if
handled = true
end if
谢谢你。
解决方案
在这里检查。
您应该使用 .setFocus(true) 和 .hasFocus(),它们可用于大多数可渲染节点,例如 TextEditBox 和 Button。
例如
if key = "down" then
if textBox1.hasFocus() then
textBox2.setFocus(true)
elseif textBox2.hasFocus() then
button.setFocus(true)
end if
end if
if key = "up" then
if button.hasFocus() then
textBox2.setFocus(true)
elseif textBox2.hasFocus() then
textBox1.setFocus(true)
end if
end if