安卓:生成随机颜色的点击? [英] Android: Generate random color on click?

查看:175
本文介绍了安卓:生成随机颜色的点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ImageView ,其中我programmaticly创建可绘制和$ P $他们psenting给用户。我的目标是点击所说的ImageView ,改变绘制的颜色。

我怎么会去随机变色位?我目前正在与修修补补随机() Col​​or.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆