Skip to content

Instantly share code, notes, and snippets.

@foxicode
Last active March 15, 2020 18:28
Show Gist options
  • Select an option

  • Save foxicode/08c2a58949429688f2c2dc624345cebb to your computer and use it in GitHub Desktop.

Select an option

Save foxicode/08c2a58949429688f2c2dc624345cebb to your computer and use it in GitHub Desktop.
Kotlin String extension to parse hex colors (Android)
import android.graphics.Color
val String.asColor: Int?
get() = try {
Color.parseColor(this)
} catch (e: java.lang.IllegalArgumentException) {
null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment