Java / Android字符串到颜色转换 [英] Java/Android String to Color conversion
问题描述
我正在制作应用程序,我希望能够通过用户输入(edittext)和十六进制值设置各种颜色,例如#eeeeee等。
如果我在代码中做这样的事情,它可以正常工作:
titlebar.setBackgroundColor(0xFF545455) ;
然而,如果我通过edittext检索到一个值,那就说545455,我无法得到它的工作
String tbColor = tb_color.getText()。toString();
字符串值=0xFF+ tbColor;
int setColor = Integer.valueOf(value);
titlebar.setBackgroundColor(setColor);
任何人都有关于如何完成此操作的想法?
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html#parseInt(java.lang.String ,int) p>
例如:
titlebar.setBackgroundColor(Integer.parseInt(545455 ,16)+ 0xFF000000);
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: titlebar.setBackgroundColor(0xFF545455);
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);
titlebar.setBackgroundColor(setColor);
Anyone have any ideas on how to accomplish this?
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html#parseInt(java.lang.String, int)
For example:
titlebar.setBackgroundColor(Integer.parseInt("545455", 16)+0xFF000000);
这篇关于Java / Android字符串到颜色转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!