1

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

Tips48
  • 745
  • 2
  • 11
  • 26
anata
  • 97
  • 2
  • 12

1 Answers1

1

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?

Community
  • 1
  • 1
Rachita Nanda
  • 4,509
  • 9
  • 42
  • 66