简体   繁体   English

为什么我不能创建新颜色

[英]Why can't I create a New Color

When I try to create a color using the RGB values I get a message saying "Color() in Color cannot be applied to:" and then its says "Expected parameter:" and "Actual Arguments:" 当我尝试使用RGB值创建颜色时,我收到一条消息,提示“ Color()in Color无法应用于:”,然后显示“ Expected parameter:”和“ Actual Arguments:”。

import android.graphics.Color;

Color myColor = new Color (0,0,0); 

When I try to run the program it says: 当我尝试运行该程序时,它说:

error: constructor Color in class Color cannot be applied to given types;
required: no arguments
found: int,int,int
reason: actual and formal argument lists differ in length

I'm going to say it's 我要说的是

//Color black
Color myColor = Color.valueOf(0.0f,0.0f,0.0f);

according to @esqew's documentation . 根据@esqew的文档 Remember that values are in the range [0,1], not [0,255] 请记住,值在[0,1]范围内,而不是[0,255]

Alternatively, as @DaveNewton suggested, we can use either of the following: 或者,按照@DaveNewton的建议,我们可以使用以下任一方法:

//Color white
Color myColor = Color.valueOf(Color.rgb(1.0f,1.0f,1.0f));//floats, [0,1]
Color myColor = Color.valueOf(Color.rgb(255,255,255));//ints, [0,255]

These methods are documented here , here , and here . 这些方法记录在此处此处此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM