HarshitVaish
10/1/2016 - 7:21 AM

SnackBar

SnackBar


dependencies {
    compile 'com.android.support:design:24.2.1'
}

// Simple snackbar
Snackbar.make(v, "Text to display", Snackbar.LENGTH_LONG).show();

// Snackbar with action
Snackbar snackbar = Snackbar.make(v, "Text to display", Snackbar.LENGTH_LONG);
snackbar.setAction("Action Text", new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        // Handle action here
      }
});

// Customizing the snackbar
View snackbarLayout = snackbar.getView();
snackbarLayout.setBackgroundColor(Color.WHITE);

TextView textView = (TextView) snackbarLayout.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.RED);

//snackbar.setActionTextColor(Color.BLUE);

Button button = (Button) snackbarLayout.findViewById(android.support.design.R.id.snackbar_action);
button.setTextColor(Color.BLACK);

snackbar.show();