mum
mum

Reputation: 1645

How convert color code to hex?

How to convert color code to code hex in android ? I am getting this color code from webservice, so i have to convert it to hex for my using it.

Ex:  0x59b512 -> #12b559

Thanks!

Upvotes: 0

Views: 317

Answers (1)

Jivan
Jivan

Reputation: 1320

Your question is not so clear. If you need to use hex coded colors in .xml files then, you need to create a set of styles in your xml (regularly in res/values/styles.xml). e.g.

<color name="gray">#eaeaea</color>
<color name="titlebackgroundcolor">#00abd7</color>
<color name="titlecolor">#666666</color>

In the layout files you can call to the colors or styles:

android:textColor="@color/titlecolor"

Comment if you've problems.

Edited: you can try to convert it into hex by using this:

String strColor = String.format("#%06X", Color);

Then use strColor to set your background.

Upvotes: 1

Related Questions