Android Color (setColor in Paint) Needs Negative Integer?
android
Solution
The problem is that `0x0000ff00` is not green, but fully transparent green. Fully opaque green would be `0xff00ff00` which is, as you have already noticed, `-16711936`. Similarly, when using `setARGB` you need to specify `255` for alpha for the color to be fully opaque.
Problem
I'm simply trying to paint/draw to the Canvas in Android. However, when I set the color using hex values or using the setARGB method, it doesn't work. But when I use Color.x (eg, Color.GREEN) it works. Here's the code: ``` Bitmap image = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(image); Paint paintBackground = new Paint(); int green = Color.argb(0, 0, 255, 0); // 65280 (Won't work) green = 0x0000ff00; // 65280 (Won't work) paintBackground.setARGB(0, 0, 255, 0); green = paintBackground.getColor(); // 65280 (Won't work) green = Color.GREEN; // -16711936 (Works!) paintBackground.setColor(green); green = paintBackground.getColor(); // -16711936 paintBackground.setStyle(Paint.Style.FILL); canvas.drawRect(0, 0, bitmapWidth, bitmapHeight, paintBackground); ``` So basically Color.GREEN returns -16711936 - and this WORKS. However, the hex value is 65280 - and this DOES NOT WORK. That is, it doesn't paint the green rectangle. I need to use hex values because I need to set the color to `0x00ffff00` here and then later to a different hex value. Does Android Color (setColor in Paint) Need a Negative Integer?