build.gradle
compile 'com.android.support:appcompat-v7:25.3.0'
MainActivity.java
public class MainActivity extends AppCompatActivity { Button buttonShow; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buttonShow= (Button) findViewById(R.id.buttonShow); buttonShow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.make(v,"Hello World",Snackbar.LENGTH_LONG).show(); } }); } }
Snackbar Actions
public void showSnackbar(View view, String message, int duration) { // Create snackbar final Snackbar snackbar = Snackbar.make(view, message, duration); // Set an action on it, and a handler snackbar.setAction("DISMISS", new View.OnClickListener() { @Override public void onClick(View v) { snackbar.dismiss(); } }); snackbar.show(); }
References
https://github.com/mhdr/AndroidSamples/tree/master/058
https://spin.atomicobject.com/2017/07/10/android-snackbar-tutorial/