How to show that an icon has the focus?

U

unba1300

Guest
Hi. Still working on my first app. Now I'd like to replace the standard buttons with icons. I did this in the designer with statelistdrawable, but when I use the keypad in the emulator to select an icon, its appearance does not change. Is there a way to show that an icon has the focus? The standard buttons would change to an orange color in this case. Thanks.
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
You could change the image of the button when it is clicked (for example to one with a different background color), and activate a timer which will switch the image back to the original when the timer event is triggered (say 500 to 1000 milliseconds). This would give the user feedback that they had pressed the button.
 
Upvote 0
U

unba1300

Guest
Thanks for your answer, but that's not the issue. I already have a different statelistdrawable for when the button is clicked. The problem is that I don't see any difference when the icon is selected (not yet clicked - but has the focus) by using the keypad in the emulator (I don't have a real device yet). Maybe this shouldn't be a concern? On a real device, would the buttons always be touched rather than navigated to by using a keypad? Thanks.
 
Upvote 0

joseluis

Active Member
Licensed User
Longtime User
I as well want to do this at some point. The way to achieve this is by modifying the StateListDrawable of the button, by code.
StateListDrawable is a drawable objects that holds other drawables. Based on the view's current state a child drawable is selected.
StateListDrawable holds a list of states. States can be "disabled", "enabled", "checked" and so on.
A state can also be a combination of other states (like enabled and pressed).


Here are more examples:
 
Last edited:
Upvote 0
Top