Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created Aug 27, 2021
Embed
What would you like to do?
Kotlin - How to use Snackbar 5
package com.example.sample
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.google.android.material.snackbar.Snackbar
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Snackbar.make(findViewById(R.id.layout), "こんにちは!", Snackbar.LENGTH_SHORT).show()
}
fun showSnackbar(view: View) {
Snackbar.make(view, "ここにメッセージを表示します", Snackbar.LENGTH_SHORT)
.setAction("ボタン") {
// ボタンを押した時の処理
}
.show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment