Android
-
[Kotlin] Scoping Functions apply vs. with, let, also, and runAndroid 2020. 11. 4. 15:06
Here is the definition of all 5 functions: inline fun with(receiver: T, block: T.() -> R): R { return receiver.block() } inline fun T.also(block: (T) -> Unit): T { block(this) return this } inline fun T.apply(block: T.() -> Unit): T { block() return this } inline fun T.let(block: (T) -> R): R { return block(this) } inline fun T.run(block: T.() -> R): R { return block() } using apply val peter = ..
-
[Android] Html을 Textview에서 보여주기 in KotlinAndroid 2020. 10. 28. 11:27
fun String.toSpanned(): Spanned { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY) } else { @Suppress("DEPRECATION") return Html.fromHtml(this) } } 확장함수를 추가해서 아래처럼 사용 tv.text = "HTML TEXT".toSpanned()