当我尝试使用RGB值创建颜色时,我收到一条消息,提示“ Color()in Color无法应用于:”,然后显示“ Expected parameter:”和“ Actual Arguments:”
import android.graphics.Color;
Color myColor = new Color (0,0,0);
当我尝试运行程序时,它说:
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
答案 0 :(得分:1)
我要说的是
//Color black
Color myColor = Color.valueOf(0.0f,0.0f,0.0f);
根据@esqew的documentation。请记住,值在[0,1]范围内,而不是[0,255]
或者,按照@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]