Wednesday, October 16, 2013

Convert hex string to color in Android

I got a hex string from resource file, looks like this "#FF00BB00". I wanna to use it as a view's background color. In Java there is a function Color.decode(String), while it is not existed on Android.

But after read the of Android quickly there is a same and useful function Color.parseColor(String), just be careful the string shall format to "#FF123456" or "#123456".

Here is the code:

No comments:

Post a Comment

Thrift fails on Windows - thrift failed error: The command line is too long.

Meet a thrift compiling failure on my project on Windows 7. Using Maven in IntelliJ so I choiced maven-thrift-pluging for thrift files. For ...