[英]Multi-colored Grid
我的任务是为 3 种不同类型的益智游戏制作游戏生成器。 我只需要完成 Bejeweled 的最后一场比赛。 我已经使用填充了按钮的 GridLayout 制作了网格。
我只需要在所有按钮上应用 7 种不同的颜色。 我之前尝试过使用此代码:
String[] backgroundColors = {"CYAN","PINK","YELLOW"};
int number = (int)(Math.random() * 3);
String c = (backgroundColors[number]);
(然后在我将按钮添加到窗格后,我添加了这个:)
buttonBejeweled.setBackgroundColor(c);
它失败了。 我想也许我应该使用和数组,但我搜索过,但不幸的是没有找到。 请帮助我使用随机颜色生成器,最好使用数组。
您可以使用
Color[] backgroundColors = {Color.RED,Color.GREEN,Color.BLUE};
int number = (int)(Math.random() * 3);
Color c = (backgroundColors[number]);
.setBackgroundColor() 是否使用字符串参数? 如果它不起作用,我猜它使用了一个颜色类型的参数。 您是否导入了颜色库? 如果没有,要访问颜色,您必须使用 Color 类并使用 Color.CYAN 访问颜色,例如,您会这样做
Color[] backgroundColors = {Color.CYAN,Color.PINK,Color.YELLOW};
int number = (int)(Math.random() * 3);
Color c = (backgroundColors[number]);
buttonBejeweled.setBackgroundColor(c);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.