Skip to content

Instantly share code, notes, and snippets.

@vedant1811
Created June 6, 2018 07:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vedant1811/ec9ceb6ce2731281ad070255f52edb3a to your computer and use it in GitHub Desktop.
Save vedant1811/ec9ceb6ce2731281ad070255f52edb3a to your computer and use it in GitHub Desktop.
Useful android kotlin extensions
/**
* Use as `"#fff".parseColor()`
*/
fun String.parseColor() = Color.parseColor(this)
/**
* Use as `16.spToPx(context)` or `16.5.spToPx(context)`
*/
fun Number.spToPx(context: Context) = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, this.toFloat(), context.resources.displayMetrics).toInt()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment