Android Question No touchscreen

Philip Prins

Active Member
Licensed User
Longtime User
Hello,

I have a device with no touchscreen but a screen with hardware up and down buttons.

How can i highlight an object,button on the screen?

I can select and press using hardware buttons but I can not see which icon/button selected.

Regards
Philip
 

Cableguy

Expert
Licensed User
Longtime User
Goodmorning,

I use buttons with a Bitmapdrawable , are these focusable views?

Regards,Philip
They are, BUT, once (and depending on how) the button is visually customized, specially by changing it to an image, the highlight may be almost unnoticeable! I would suggest that you use the "focused" event and add your own higlhighl to the button
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I have no focus event for buttons.

https://stackoverflow.com/questions/3234607/how-to-set-focus-to-a-button-widget-programmatically
Important Note: The button widget needs to be focusable and focusableInTouchMode. Most widgets are focusable but not focusableInTouchMode by default. So make sure to either set it in code

Based on this you need to use JavaObject to make the Button fucusable.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    
    Button1.Enabled = False
    addstatelist(Button1)
    
    Button2.RequestFocus
    addstatelist(Button2)
    addstatelist(Button3)
    addstatelist(Button4)
    addstatelist(Button5)
End Sub
Sub addstatelist(btn As Button)
    Dim jo As JavaObject = btn
    jo.RunMethod("setFocusableInTouchMode",Array As Object(True))
    jo.RunMethod("setFocusable",Array As Object(True))
    Dim focused, pressed, selected, disabled, enabled As ColorDrawable
    focused.Initialize2(Colors.Gray,5dip, 5dip, Colors.White)
    pressed.Initialize2(Colors.DarkGray,5dip, 5dip, Colors.Blue)
    selected.Initialize2(Colors.Yellow,5dip, 5dip, Colors.Magenta)
    disabled.Initialize2(Colors.DarkGray,5dip, 5dip, Colors.Red)
    enabled.Initialize2(Colors.Black, 5dip, 5dip, Colors.Green)

    Dim sld As StateListDrawable
    sld.Initialize
    sld.AddState(sld.State_Focused, focused)
    sld.AddState(sld.State_Pressed, pressed)
    sld.AddState(sld.State_Selected, selected)
    sld.AddState(sld.State_Disabled, disabled)
    sld.AddState(sld.State_enabled, enabled)

    btn.Background = sld   
End Sub
Sub Activity_Resume
    Button5.RequestFocus
End Sub
 

Attachments

  • StateListEx.zip
    9.5 KB · Views: 135
Upvote 0
Top