Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created February 5, 2021 06:15
Show Gist options
  • Save codeforfun-jp/943f8d96826226fe0950b919da720d8e to your computer and use it in GitHub Desktop.
Save codeforfun-jp/943f8d96826226fe0950b919da720d8e to your computer and use it in GitHub Desktop.
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;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Snackbar.make(findViewById(R.id.layout), "こんにちは!", Snackbar.LENGTH_SHORT)
.show();
}
public void showSnackbar(View view) {
Snackbar.make(view, "ここにメッセージを表示します", Snackbar.LENGTH_SHORT)
.setAction("ボタン", new View.OnClickListener() {
@Override
public void onClick(View v) {
// ボタンを押した時の処理
}
})
.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment