Kotlin extensions

At the end of this chapter, I would like to introduce you to the Kotlin extensions. No, not exactly the Kotlin extensions functions, although they are very much related to the Kotlin extension functions. Kotlin extensions is a curated list of the most commonly used extension functions in Android.

For example, if you want an extension function to create a bitmap from a View/ViewGroup instance (especially useful while adding Markers in MapFragment), you can copy and paste the following extension function from there:

    fun View.getBitmap(): Bitmap { 
      val bmp = Bitmap.createBitmap(width, height,      Bitmap.Config.ARGB_8888) 
      val canvas = Canvas(bmp) 
      draw(canvas) 
      canvas.save() 
      return bmp 
    } 

Or, a more common case, when you need to hide ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.