安卓:生成随机颜色的点击? [英] Android: Generate random color on click?
问题描述
我有一个的ImageView
,其中我programmaticly创建可绘制和$ P $他们psenting给用户。我的目标是点击所说的ImageView
,改变绘制的颜色。
我怎么会去随机变色位?我目前正在与修修补补随机()
, Color.argb()
和一些其它的东西,但我可以'不像是会得到它的工作!
随机RND =新的随机();
paint.setARGB(255,rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256));
或
随机RND =新的随机();
INT颜色= Color.argb(255,rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256));
view.setBackgroundColor(颜色);
虽然你的情况看来,要创建一个新的绘制,并将其分配给您的视图。其实什么是你的情况下,绘制?它是一个图像,形状,填充...
I have an ImageView
, in which I am programmaticly creating drawables and presenting them to the user. My goal is to click on said ImageView
and change the drawable's color.
How would I go about the random color changing bit? I am currently tinkering with Random()
, Color.argb()
and a few other things, but I can't seem to get it to work!
Random rnd = new Random();
paint.setARGB(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
or
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
view.setBackgroundColor(color);
Though in your case it seems that you want to create a new drawable and assign it to your view. What is actually the drawable in your case? Is it an image, shape, fill...
这篇关于安卓:生成随机颜色的点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!