且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java / Android字符串到颜色转换

更新时间:2023-11-07 10:39:34

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);