Last active
March 15, 2020 18:28
-
-
Save foxicode/08c2a58949429688f2c2dc624345cebb to your computer and use it in GitHub Desktop.
Kotlin String extension to parse hex colors (Android)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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