Skip to content

Instantly share code, notes, and snippets.

@maiconhellmann
Created November 21, 2017 16:40
Show Gist options
  • Save maiconhellmann/70547df808f12437452518c0399b23b2 to your computer and use it in GitHub Desktop.
Save maiconhellmann/70547df808f12437452518c0399b23b2 to your computer and use it in GitHub Desktop.
Kotlin extensions for View
import android.support.design.widget.Snackbar
import android.view.View
import com.github.clans.fab.FloatingActionMenu
fun View.visible(){
this.visibility = View.VISIBLE
}
fun View.visible(visible : Boolean){
if(visible){
visible()
}else{
gone()
}
}
fun View.gone(){
this.visibility = View.GONE
}
fun View.invisible(){
this.visibility = View.INVISIBLE
}
fun View.snackbar(resId: Int, duration: Int = Snackbar.LENGTH_SHORT) {
snackbar(this.resources.getString(resId), duration)
}
fun View.snackbar(msg: String, duration: Int = Snackbar.LENGTH_SHORT) {
Snackbar.make(this, msg, duration).show()
}
fun View.longSnackbar(resId: Int) {
snackbar(resId, Snackbar.LENGTH_LONG)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment