Created
February 1, 2019 10:42
-
-
Save albertogarrido/646c16d47b28150664337bbf92bbf69c to your computer and use it in GitHub Desktop.
Android view visibility extension functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.view.View | |
fun View.visible() { | |
visibility = View.VISIBLE | |
} | |
fun View.invisible() { | |
visibility = View.INVISIBLE | |
} | |
fun View.gone() { | |
visibility = View.GONE | |
} | |
fun View.isGone() = visibility == View.GONE | |
fun View.isVisible() = visibility == View.VISIBLE | |
fun View.isInvisible() = visibility == View.INVISIBLE | |
fun View.toggleVisibleGone() { | |
if (isGone()) visible() | |
else if (isVisible()) gone() | |
} | |
fun View.toggleVisibleInvisible() { | |
if (isInvisible()) visible() | |
else if (isVisible()) invisible() | |
} | |
fun View.toggleGoneInvisible() { | |
if (isInvisible()) gone() | |
else if (isGone()) invisible() | |
} | |
fun View.toggleVisibleAndOthersGone(vararg others: View) { | |
visible() | |
others.forEach { | |
it.gone() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment