简体   繁体   中英

Change from ARGB Color to RRGGBB color

I want to set the values: Red: 0.910 green: 0.969 blue: 0.996 alpha: 1.0
I get color as:

int color=Color.argb(1.0,0.910,0.969,0.996)

but this doesn't work.

I want to get the value in hex color as #FF00FF. Any advice?

Thanks

Use this to get Hex values

protected int toHex(Color col) {
        String as = pad(Integer.toHexString(col.getAlpha()));
        String rs = pad(Integer.toHexString(col.getRed()));
        String gs = pad(Integer.toHexString(col.getGreen()));
        String bs = pad(Integer.toHexString(col.getBlue()));
        String hex = "0x" + as + rs + gs + bs;
        return Integer.parseInt(hex, 16);
    }

    private static final String pad(String s) {
        return (s.length() == 1) ? "0" + s : s;
    }

eg : int color = toHex(new Color(1f, 1f, 1f, 1f));

Here's the link I refered to Convert RGBA values to hex color code

Related Links:

How to convert a color integer to a hex String in Android?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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