Android-er: Simplest Snackbar

Dhanisa Mashilfa

Snackbars
deliver lightweight feed-back about an operation. They exhibit a quick concept
at the base of the monitor on cellular and decrease still left on bigger gadgets.
Snackbars surface over all other aspects on monitor and only a single can be
shown at a time.

They quickly vanish following a timeout
or after person conversation somewhere else on the monitor, significantly right after
interactions that summon a new floor or action. Snackbars can be swiped
off display.

It really is a most basic case in point to show Snackbar applying Kotlin. The
format xml is very same as past put up “Very simple case in point of Button and Toast”.

MainActivity.kt

bundle android_er.blogspot.com.myapp01

import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.application.AppCompatActivity
import com.google.android.materials.snackbar.Snackbar

non-public lateinit var btnA: Button
personal lateinit var btnB: Button

course MainActivity : AppCompatActivity() 
    override pleasurable onCreate(savedInstanceState: Bundle?) 
        super.onCreate(savedInstanceState)
        setContentView(R.format.activity_key)

        btnA = findViewById(R.id.btn_A)
        btnB = findViewById(R.id.btn_B)

        btnA.setOnClickListener(
             look at: See ->
                Toast.makeText(
                    this,
                    "Button A pressed",
                    Toast.Duration_Prolonged,
                ).display()
            ,
        )

        btnB.setOnClickListener(
             see: Check out ->
                val snackbar = Snackbar
                    .make(btnB,
                        "android-er.blogspot.com",
                        Snackbar.Length_Lengthy)
                snackbar.show()
            ,
        )
    

Next Post

Simple example of Button and Toast (Android Kotlin)

action_primary.xml MainActivity.kt deal android_er.blogspot.com.myapp01 import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Perspective import android.widget.Button import android.widget.Toast private lateinit var btnA: Button non-public lateinit var btnB: Button class MainActivity : AppCompatActivity() override enjoyment onCreate(savedInstanceState: Bundle?) tremendous.onCreate(savedInstanceState) setContentView(R.structure.action_primary) btnA = findViewById(R.id.btn_A) btnB = findViewById(R.id.btn_B) btnA.setOnClickListener( view: See -> Toast.makeText( this, "Button A pressed", Toast.Length_Very […]
Simple example of Button and Toast (Android Kotlin)