0

I have a custom ImageButton in which I have placed a png and the hover Image which is transparent from some parts. So when It gets focused it also takes it self with a blue focus. I want to remove that focus blue color but at the same time I want my hoverImage to work!
This is my ImageButton Class: http://codepad.org/mjtIUKLR

Ahmad Shahwaiz
  • 1,432
  • 1
  • 17
  • 35
  • Please don't link to your code stored elsewhere. Post your code here, and use the **{ }** button to format it as code. If you don't do that, then future visitors to the site can't get much useful information out of this question, because the link to your code may be dead. Thanks. – Nate Jan 29 '13 at 23:38
  • 1
    Check this, http://stackoverflow.com/questions/2816937/removing-the-default-blue-color-on-focus. Also try overriding Field.applyTheme(). – Rupak Jan 30 '13 at 05:29
  • @Nate Alright man! @ Rupak, Yeah it worked. – Ahmad Shahwaiz Jan 30 '13 at 10:02

1 Answers1

2

A solution that works for me is to add this functionality to the paint method and track whether focus has been gained:

boolean hasFocus = false;
public void onFocus(int direction) {
    invalidate();
    hasFocus = true;
}

public void onUnfocus() {
    hasFocus = false;
    invalidate();
    super.onUnfocus();
}

And then use this in your paint method:

public void paint(Graphics graphics) {
    if (hasFocus){
        graphics.drawShadedFilledPath(xPositions, yPositions, null,      
                                      HIGHLIGHTED_GRADIENT, null);
    }else{
        graphics.drawShadedFilledPath(xPositions, yPositions, null,      
                                      GRADIENT, null);      
    }
   super.paint(graphics);
}

In my example above, I am using a custom gradient for highlighting that overrides the default blue colour. In your case you will obviously want to change your image or something.

biddulph.r
  • 5,226
  • 3
  • 32
  • 47