我希望我的代码自动选择随机颜色...目前我将其静态...我希望它改变颜色时它,只需随机选择 RGB 世界中的任何颜色...
以下是我所拥有的,非常感谢我能得到的任何帮助!
private float[][] BackgroundColors = { { 141, 189, 193 }, { 116, 84, 62 },
{ 73, 113, 116 }, { 193, 163, 141 }, { 15, 11, 6 }, };
private void getCurrentColor() {
CurrentColorNumber++;
if (CurrentColorNumber >= 5) {
CurrentColorNumber = 0;
}
CurrentColor = new Color(
BackgroundColors[CurrentColorNumber][0] / 255.0f,
BackgroundColors[CurrentColorNumber][1] / 255.0f,
BackgroundColors[CurrentColorNumber][2] / 255.0f, 1);
}
最佳答案
假设我有一个 TextView ,并且我想要文本的随机颜色 每次点击按钮时。 只需在您的程序中检查此代码即可。 我希望这个逻辑对你有帮助。
TextView Display = (TextView) findViewById(R.id.tvresult);
Random mRandom = new Random();
Display.setText("WHAT????");
Display.setTextSize(mRandom.nextInt(75));
Display.setTextColor(Color.rgb(mRandom.nextInt(265),
mRandom.nextInt(265), mRandom.nextInt(265)));
关于java android 随机颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29795959/