Created
June 6, 2018 07:15
-
-
Save vedant1811/ec9ceb6ce2731281ad070255f52edb3a to your computer and use it in GitHub Desktop.
Useful android kotlin extensions
This file contains 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
/** | |
* 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