我正在创建一个应用程序,我希望能够通过用户输入(edittext)和十六进制值设置各种颜色,例如#eeeeee等.问题是我似乎无法弄清楚如何转换它们.
如果我在这样的代码中做一些事情就可以了:titlebar.setBackgroundColor(0xFF545455);
但是,如果我通过edittext检索一个值,说"545455"我无法让它工作
String tbColor = tb_color.getText().toString();
String value = "0xFF" + tbColor;
int setColor = Integer.valueOf(value);
titlebar.setBackgroundColor(setColor);
Run Code Online (Sandbox Code Playgroud)
任何人对如何实现这一点有任何想法?
the*_*ejh 20
例如:
titlebar.setBackgroundColor(Integer.parseInt("545455", 16)+0xFF000000);
Run Code Online (Sandbox Code Playgroud)