Skip to content

Instantly share code, notes, and snippets.

@NikCapko
Created March 21, 2023 21:09
Show Gist options
  • Save NikCapko/07e35b031553d4e276cfb7b38cadd803 to your computer and use it in GitHub Desktop.
Save NikCapko/07e35b031553d4e276cfb7b38cadd803 to your computer and use it in GitHub Desktop.
Change view visibility
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