title: Color from hex string in jetpack compose
body: <p>How to parse hex string e.g. <code>#9CCC65</code> in <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:ui/ui-graphics/src/main/java/androidx/ui/graphics/Color.kt" rel="noreferrer">Color</a> class in jetpack compose. </p>
  
  <p><strong>P.S: option seem to be missing in jetpack compose package</strong></p>
  
  <hr>
  
  <p><strong>Current Workaround:</strong>
  Exported <code>parseColor()</code> method from standard Color class. </p>
  
  <pre><code>@ColorInt
  fun parseColor(@Size(min = 1) colorString: String): Int {
      if (colorString[0] == '#') { // Use a long to avoid rollovers on #ffXXXXXX
          var color = colorString.substring(1).toLong(16)
          if (colorString.length == 7) { // Set the alpha value
              color = color or -0x1000000
          } else require(colorString.length == 9) { "Unknown color" }
          return color.toInt()
      }
      throw IllegalArgumentException("Unknown color")
  }
  </code></pre>