2

When I create a Button,

Button myButton = new Button(this);
myButton.setText("Click Me!");

it creates a button, that on click, turns "Orange" to indicate the click.

To the button when I add,

button.setBackgroundColor(Color.BLUE);

It creates a blue rectangle, and on click does not have a hightlight effect.

I don't mind the rectangle part, I want to get the orange highlight effect though.

Cannot use XML, need to do this in code.

Thanks

Quintin Robinson
  • 81,193
  • 14
  • 123
  • 132
Chris
  • 3,787
  • 13
  • 42
  • 49

2 Answers2

2

For setting background color/image and having click highlight effect....you have set the style/theme for the button.

The style/theme contains the color attributes for various states of button such as focused / enabled / disabled/ etc.

Daniel
  • 20,420
  • 10
  • 92
  • 149
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • @chris....Generally you cant change style of any control programmatically...refer this answer(http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view/2016344#2016344) this makes your doubt clear..... – Paresh Mayani Jul 21 '10 at 08:32
1

I have the same problem with you and fixed it strangely. You need to type button.setBackgroundColor(android.graphics.Color.GREEN);, because we didn't import class android.graphics.Color. Good luck! :D.

animuson
  • 53,861
  • 28
  • 137
  • 147
Storm Boy
  • 11
  • 2