View extensions

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

fun View.show() {    this.visibility = View.VISIBLE}fun View.hide() {    this.visibility = View.GONE}

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

emailPasswordButtons.hide()emailPasswordFields.hide()signedInButtons.show()
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

Get Hands-On Serverless Applications with 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.