为什么CustomButton结果为灰色?在R.color.blue中,绿色和红色真的是红色,蓝色和红色。我试图从colors.xml中随机选择颜色为红蓝绿色的按钮颜色。如何在阵列颜色中设置按钮背景?
public void CustomButton(int btnId) {
Button btn = (Button) findViewById(btnId);
int[] btnColor = { R.color.blue, R.color.green, R.color.red };
Random random = new Random();
int c = btnColor[random.nextInt(btnColor.length)];
btn.setBackgroundColor(c);
}
我不完全确定你在做什么,但如果你想随机化按钮的颜色,我认为这可能会帮助你 - > http://stackoverflow.com/questions/6185931/how-设置按钮颜色 – Hanut 2013-04-08 17:24:29