views:

113

answers:

1

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

A: 

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.

Refer this Example where you get the full idea for setting background image or color to the button.

Hope this example helps you.

Enjoy !!!

PM - Paresh Mayani
Any way of doing this programatically, in code?
Chris
@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.....
PM - Paresh Mayani