Toast y SnackBar en Android

Toast

Toast.makeText(this,"Hello from the Toast",Toast.LENGTH_LONG).show() //Parametros: (Contexto,Texto,Duracion)

 

Snackbar

Añadir al Gradle:

implementation 'com.android.support:design:27.0.0'

**Versiones de  las Librerías de Soporte

 

val layout = findViewById<ConstraintLayout>(R.id.constraint)

Snackbar.make(layout,"Hello fron SnackBar!",Snackbar.LENGTH_LONG).show()//Igual que el Toast pero le pasas un View

 

Snackbar con Botón

  ==Action Button==> 

Snackbar.make(layout,"Hello fron SnackBar!",Snackbar.LENGTH_LONG).setAction("UNDO") { // Parametros de setAction(Texto, Action ó Callback))
     Snackbar.make(layout,"Email has been restored!!",Snackbar.LENGTH_LONG).show()
}.show()