Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
chaklasiyanikun
Level 11

Is there any way to set by default key focus inside init() or inside XML component

My Button is below. I tried to focusBitmapUri set in XML and also set in init(). I need to button the focus image when the application launch. So, I set this field in init(). I tried focusable = "true". But no luck.

My XML File :

<Button id="Button" iconUri="" focusedIconUri="" showFocusFootprint="true" 
focusFootprintBitmapUri="pkg:/images/button.png" minWidth="150" focusable="true"
height="50" translation="[440,500]" />

My brs File :

sub init()
     m.Button = m.top.findNode("Button") 
     ?m.Button.hasFocus()
     m.Button.focusBitmapUri = "pkg:/images/newsignin.png"
     m.Button.iconUri = ""
     m.Button.focusedTextColor = "0x00000000"
     m.Button.setFocus(true)
     ?m.Button.hasFocus()
     ?"m.Button.focusFootprintBitmapUri : "m.Button.focusFootprintBitmapUri
     ?"m.Button.focusBitmapUri : " m.Mac_Login.focusBitmapUri
     m.top.SetFocus(true)
end sub

It's Completely Working fine. After, I set this field in onkeyEvent. In Documentation said this field worked after key focus. But, Is there any way to set by default key focus to this button when the application launches and init().

function onKeyEvent(key as String, press as Boolean) as Boolean
     result = false
     if key = "OK" then
          m.Button.focusBitmapUri = "pkg:/images/Button.png"
          m.Button.iconUri = ""
          m.Button.focusedTextColor = "0x00000000"
          m.Button.setFocus(true)
          ?m.Button.hasFocus()
          ?"m.Button.focusFootprintBitmapUri : "m.Button.focusFootprintBitmapUri
          ?"m.Button.focusBitmapUri : " m.Button.focusBitmapUri
         result = true
     end if
     return result 
end function
0 Kudos
2 Replies
RokuNB
Roku Employee
Roku Employee

Re: Is there any way to set by default key focus inside init() or inside XML component

     m.Button.setFocus(true)
...
     m.top.SetFocus(true)

first you set the focus on the button, then on the parent. 

The input focus can be "focused" on only one widget at a time - the last one on which setFocus(true) was called - in this case it is the "parent" component. Commenting out `m.top.SetFocus(true)` should fix it?

0 Kudos
chaklasiyanikun
Level 11

Re: Is there any way to set by default key focus inside init() or inside XML component

@RokuNB Thank you for your reply, I don't know this is a better way or not. I solved this issue using Create one separate Component and set by default focus like below and use in the main scene in init().

<Component id = "MyComponentName" extends = "Group" initialFocus = "Button">
.....
.....
</Component>
0 Kudos