我正在尝试创建使用随机颜色的小应用程序。
Random rnd = new Random();
int color1 = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
int color2 = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
int color3 = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
但在 color1、color2 和 color3 中保存了诸如“-11338194”之类的值。是否可以取argb值? (比如“255255255255”之类的)谢谢!
最佳答案
试试这个代码,
Random rnd = new Random();
int color1 = Color.argb(255, rnd.nextInt(256 - 0), rnd.nextInt(256 - 0), rnd.nextInt(256 - 0));
int color2 = Color.argb(255, rnd.nextInt(256 - 0), rnd.nextInt(256 - 0), rnd.nextInt(256 - 0));
int color3 = Color.argb(255, rnd.nextInt(256 - 0), rnd.nextInt(256 - 0), rnd.nextInt(256 - 0));
关于java - int argb color 输出奇怪的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38190790/