Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e4basil/03dec962d1a8ed44878e5706a2141e10 to your computer and use it in GitHub Desktop.
Save e4basil/03dec962d1a8ed44878e5706a2141e10 to your computer and use it in GitHub Desktop.
Kotlin Extension functions for handling the view visibility in android
import android.view.View
fun View.gone() = run { visibility = View.GONE }
fun View.visible() = run { visibility = View.VISIBLE }
fun View.invisible() = run { visibility = View.INVISIBLE }
infix fun View.visibleIf(condition: Boolean) =
run { visibility = if (condition) View.VISIBLE else View.GONE }
infix fun View.goneIf(condition: Boolean) =
run { visibility = if (condition) View.GONE else View.VISIBLE }
infix fun View.invisibleIf(condition: Boolean) =
run { visibility = if (condition) View.INVISIBLE else View.VISIBLE }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment