Snackbars
provide light-weight suggestions about an procedure. They display a brief concept
at the base of the display screen on cellular and lessen still left on greater products.
Snackbars appear over all other elements on screen and only a single can be
shown at a time.
They automatically disappear following a timeout
or soon after user interaction elsewhere on the screen, notably right after
interactions that summon a new surface area or action. Snackbars can be swiped
off display.
It really is a most straightforward instance to show Snackbar employing Kotlin. The
structure xml is exact as final post “Uncomplicated case in point of Button and Toast”.
MainActivity.kt
offer android_er.blogspot.com.myapp01
import android.os.Bundle
import android.see.Perspective
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.application.AppCompatActivity
import com.google.android.content.snackbar.Snackbar
private lateinit var btnA: Button
non-public lateinit var btnB: Button
course MainActivity : AppCompatActivity()
override pleasurable onCreate(savedInstanceState: Bundle?)
tremendous.onCreate(savedInstanceState)
setContentView(R.structure.action_major)
btnA = findViewById(R.id.btn_A)
btnB = findViewById(R.id.btn_B)
btnA.setOnClickListener(
look at: Perspective ->
Toast.makeText(
this,
"Button A pressed",
Toast.Length_Lengthy,
).present()
,
)
btnB.setOnClickListener(
view: Check out ->
val snackbar = Snackbar
.make(btnB,
"android-er.blogspot.com",
Snackbar.Size_Prolonged)
snackbar.show()
,
)
More Stories
On the net Online games: A Bittersweet Handle
Will a Freely Distributed OS for Smartwatches Realize success?
Go away Her Wanting Extra & Observe Her Chase You Like Nuts! Best Secrets Adult males Will have to Know