Android Lesson 13: Snackbar


Import:

import com.google.android.material.snackbar.Snackbar;

Example:

        //make snackbar
        Snackbar snackbar = Snackbar.make(view,"Item 1: A\n"+"Item 2: B\n", Snackbar.LENGTH_INDEFINITE);
        //set action
        snackbar.setAction("CLEAR", v -> {
            snackbar.setDuration(Snackbar.LENGTH_SHORT);
        });
        View v = snackbar.getView();
        TextView snackbar_text = (TextView) v.findViewById(com.google.android.material.R.id.snackbar_text);
        //change snackbar text color
        snackbar_text.setTextColor(Color.YELLOW);
        TextView snackbar_action = (TextView) v.findViewById(com.google.android.material.R.id.snackbar_action);
        //change textsize snackbar action
        snackbar_action.setTextSize( 20 );
        snackbar_action.setTypeface(snackbar_action.getTypeface(), Typeface.BOLD);
        //display snackbar
        snackbar.show();

android snackbar

More information about Snackbar:
https://github.com/material-components/material-components-android/blob/master/docs/components/Snackbar.md

Leave a Reply