开发者

Button setBackgroundColor no highlight effect

开发者 https://www.devze.com 2023-01-08 09:09 出处:网络
W开发者_如何学Pythonhen I create a Button, Button myButton = new Button(this); myButton.setText(\"Click Me!\");

W开发者_如何学Pythonhen 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消