Convert int value color to RGB String #RRGGBB - Android Graphics

Android examples for Graphics:Color RGB Value

Description

Convert int value color to RGB String #RRGGBB

Demo Code


//package com.java2s;
import android.graphics.Color;

public class Main {
    public static String toRGBString(int color) {
        // format: #RRGGBB
        String red = Integer.toHexString(Color.red(color));
        String green = Integer.toHexString(Color.green(color));
        String blue = Integer.toHexString(Color.blue(color));
        if (red.length() == 1)
            red = "0" + red;
        if (green.length() == 1)
            green = "0" + green;
        if (blue.length() == 1)
            blue = "0" + blue;
        return "#" + red + green + blue;
    }//from w ww. j a  v  a  2 s . co  m
}

Related Tutorials