我的应用程序的要求是listview项目的浅色但不透明的颜色.我得到随机颜色,但它经常很暗.而且我不知道在哪个范围内我才能获得浅色.随机给出的范围是这样的:
Random rndm = new Random();
int color = Color.argb(255, rndm.nextInt(256), rndm.nextInt(256), rndm.nextInt(256));
RelativeLayout rl=(RelativeLayout)rowView.findViewById(R.id.front);
rl.setBackgroundColor(color);
Run Code Online (Sandbox Code Playgroud)
你想要更浅的颜色.这意味着RGB分量值必须介于128和255之间.
因为Random.nextInt(int max)返回一个int between 0 inclusive and max exclusive,你可能想尝试这样的事情:
Random rnd = new Random();
int r = rnd.nextInt(128) + 128; // 128 ... 255
int g = rnd.nextInt(128) + 128; // 128 ... 255
int b = rnd.nextInt(128) + 128; // 128 ... 255
Color clr = Color.rgb(r, g, b);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1096 次 |
| 最近记录: |