View extensions

Often we need to play with the view's visibility. Extension functions can help us here. If you see in the ViewExtensions.kt file, there are two extension functions written inside:

    fun View.visible() {      this.visibility = View.VISIBLE    }    fun View.gone() {      this.visibility = View.GONE    }

So now suppose you want to change the visibility of any of the views, you can write the code in the following way:

    cardLinkedInUser.visible()    btnLoginLinkedIn.gone()
Extension functions are visible for all child classes as well. For example, we wrote the extension function for the View class. So we can call the visible() and gone() functions from any subclass of View, that is EditText, TextView, Button, CardView, RecyclerView, ListView, and so ...

Get Kotlin Blueprints 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.