Snackbars
provide light-weight responses about an operation. They present a quick message
at the base of the display on cell and decrease left on much larger equipment.
Snackbars appear earlier mentioned all other features on monitor and only 1 can be
shown at a time.
They automatically vanish after a timeout
or following consumer interaction somewhere else on the display screen, specially just after
interactions that summon a new floor or action. Snackbars can be swiped
off display screen.
It can be a easiest illustration to show Snackbar applying Kotlin. The
layout xml is similar as previous submit “Straightforward illustration of Button and Toast”.
MainActivity.kt
deal android_er.blogspot.com.myapp01
import android.os.Bundle
import android.look at.View
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.materials.snackbar.Snackbar
non-public lateinit var btnA: Button
private lateinit var btnB: Button
course MainActivity : AppCompatActivity()
override pleasurable onCreate(savedInstanceState: Bundle?)
tremendous.onCreate(savedInstanceState)
setContentView(R.structure.exercise_key)
btnA = findViewById(R.id.btn_A)
btnB = findViewById(R.id.btn_B)
btnA.setOnClickListener(
view: See ->
Toast.makeText(
this,
"Button A pressed",
Toast.Duration_Long,
).clearly show()
,
)
btnB.setOnClickListener(
see: See ->
val snackbar = Snackbar
.make(btnB,
"android-er.blogspot.com",
Snackbar.Duration_Extensive)
snackbar.demonstrate()
,
)