// Kotlin val s = SpannableStringBuilder("Hello, Spans!") s.setSpan(StyleSpan(Typeface.BOLD), 0, s.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) s.setSpan(ForegroundColorSpan(Typeface.BOLD), 7, 12, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) // KTX val s = "Hello, Spans!".toSpannable() s += StyleSpan(Typeface.BOLD) s[7..12] ForegroundColorSpan(Color.RED)
Menu item
// Kotlin for (i in 0..menu.size()) { var menuItem = menu.getItem(i) } // KTX menu.forEach { // Do action }
// Kotlin val menuItemToDel for (i in 0..menu.size()) { var menuItem = menu.getItem(i) if (menuItem == menuItemToDel) { menu.removeItem(i) } } // KTX if (menuItemToDel in menu) { menu -= menuItemToDel }
Uri
// In Kotlin val uri = Uri.parse(myUriString) // KTX val uri = myUriString.toUri()
Canvas
// In Kotlin val pathDifference = Path(myPath1).apply { op(myPath2, Path.Op.DIFFERENCE) }
val myPaint = Paint()
canvas.apply { val checkpoint = save() translate(0F, 100F) drawPath(pathDifference, myPaint) restoreToCount(checkpoint) } // KTX val pathDifference = myPath1 - myPath2
// In Kotlin Month.APRIL.ordinal // KTX Month.APRIL.asInt()
// In Kotlin val nano = Duration.ofSeconds(1).nano val seconds = Duration.ofSeconds(1).seconds // KTX val (seconds, nanoseconds) = Duration.ofSeconds(1)
// Kotlin var duration = Duration.ofSeconds(1).seconds duration /= 2 // KTX val result = Duration.ofSeconds(2) / 2