0

I have a group of buttons which enable user to select certain views on the touch screen.

I want to have the user know which view is active by showing a halo (or any other style) around the button. I mean when the button is clicked it's normal state is changed to different style but it is still normal.

I googled and checked in stackoverflow, that it is not possible to change the style at runtime. How can I achieve the desired effect? I have some silly ideas which I won't implement unless as last resort, like making two buttons at same positions and changing their visibility. Or I can put each button in it's own linear layout and then set the background color of each of them, if it is possible. Or some ImageButton manipulation maybe.

I have already overridden the default style for button for normal pressed states. And setting focus(when in focusInTouchMode) causes problem, so that's a NO (already tried that).

Even if style can't be changed, please advise some tip to achieve the effect, it's not necessary to do it the style way. I just want o let the user know which view is selected through buttons.

example image

Community
  • 1
  • 1
Master Chief
  • 2,520
  • 19
  • 28

3 Answers3

1

use state list and set its focussed state drawable as the button with a ring around it and then at runtime say button.requestFocus(). see here for more on state list...

ngesh
  • 13,398
  • 4
  • 44
  • 60
  • Setting focus was my first Idea, but I don't know why setting focus messes around with my code. – Master Chief May 07 '12 at 10:23
  • Then thats the real problem and not what you have currently posted.. why don't you post your code and show us what have you tried.. – ngesh May 07 '12 at 10:26
  • Actually setting focus, doesn't causes problem with these buttons, but some other button. When I set and use focus, if I use H/W buttons they work fine, but when I touch them, some other corresponding button work diffrently. They don't crash or anything. That's why I don't think it should be done with focus states. – Master Chief May 07 '12 at 10:36
0

Go for selector xml background for each button. Best Resort

Check this link How to set image button backgroundimage for different state?

Hpoe this helps

Community
  • 1
  • 1
Rohit Sharma
  • 13,787
  • 8
  • 57
  • 72
0

or you can use like ::

Button button;
public void onClick(View v)
{
    button.button.setBackgroundColor(**color**);
    button.setBackgroundResource(**res**)
}
Harpreet
  • 2,990
  • 3
  • 38
  • 52
  • You may want to refer to [this](http://stackoverflow.com/questions/3297027/button-setbackgroundcolor-no-highlight-effect) – Master Chief May 07 '12 at 10:32