Paul Paul - 1 year ago 112
Java Question

Java/Android String to Color conversion

I'm making an app and I'd like to be able to set various colors via user input(edittext) and hex values e.g. #eeeeee and so on. Problem is I cannot seem to figure out how to convert them.

If I do something in code like this it works fine:

However if I retrieve a value via the edittext say "545455" I cannot get it work

String tbColor = tb_color.getText().toString();
String value = "0xFF" + tbColor;
int setColor = Integer.valueOf(value);

Anyone have any ideas on how to accomplish this?

Answer Source, int)

For example:

titlebar.setBackgroundColor(Integer.parseInt("545455", 16)+0xFF000000);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download