Convert int color value to Color String - Android Graphics

Android examples for Graphics:Color Value

Description

Convert int color value to Color String

Demo Code


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

public class Main {
    public static String toColorString(int bgColor) {
        return "#" + hex2(Color.alpha(bgColor)) + hex2(Color.red(bgColor))
                + hex2(Color.green(bgColor)) + hex2(Color.blue(bgColor));
    }//ww w .  j a v a  2s  .  co m

    public static String hex2(int val) {
        String a = Integer.toHexString(val);
        if (a.length() < 2) {
            a = "0" + a;
        }
        return a;
    }
}

Related Tutorials