【发布时间】:2014-08-05 00:06:09
【问题描述】:
我想使用指示按钮颜色的代码 (id=button1) 并在颜色为蓝色时执行某些操作, 我的意思是=
如果button1的颜色是蓝色类型1,如果是绿色、黄色或其他颜色,输入game over。
我该怎么做?
我试过这样:
if(v.getId() == R.id.button1){
ColorDrawable buttonColor = (ColorDrawable) button1.getBackground();
int colorId = buttonColor.getColor();
}
有一个错误:
Multiple markers at this line
- Type mismatch: cannot convert from ColorDrawable to int
- The method getColor() is undefined for the type
如果您将鼠标悬停在 getColor() 上,则会出现另一个错误:
The method getColor() is undefined for the type ColorDrawable
我能做什么? 谢谢。
【问题讨论】:
-
我同意 Gabe 的回答。getColor() 方法仅在 API 11(Honeycomb) 及更高版本中可用。参考stackoverflow.com/a/8089242/775467
-
我不知道该怎么做..我只是一个初学者,加布的答案很难..
标签: android