//Toast Toast.makeText(this, "Click the Toast", Toast.LENGTH_SHORT).show(); //Snackbar /** * @param view The view to find a parent from. * @param text The text to show. Can be formatted text. * @param duration How long to display the message. */ Snackbar.make(mSnackBar, "Click the SnackBar", Snackbar.LENGTH_SHORT).show();
final Snackbar snackbar = Snackbar.make(mSnackBar, "Click the SnackBar", Snackbar.LENGTH_SHORT); snackbar.getView().setBackgroundColor(ContextCompat.getColor(this, R.color.orange));//set the background color for snackbar setSnackbarActionTextAllCaps(snackbar, false);//set the action text whether all caps snackbar.setAction("Cancel", new View.OnClickListener() { @Override publicvoidonClick(View view){ // if (snackbar != null && snackbar.isShown()) { // snackbar.dismiss(); // }
Snackbar snackbar1 = Snackbar.make(mSnackBar, "Click Cancel", Snackbar.LENGTH_SHORT); setSnackbarMessageTextColor(snackbar1,ContextCompat.getColor(MainActivity.this, R.color.orange)); snackbar1.show(); } }) .setText("Hello")//set the message text .setActionTextColor(ContextCompat.getColor(this, R.color.green)) .show();
/** * set the message text color * * @param snackbar * @param color the text color */ publicstaticvoidsetSnackbarMessageTextColor(Snackbar snackbar, int color){ View view = snackbar.getView(); TextView textView = (TextView) view.findViewById(R.id.snackbar_text); textView.setTextColor(color); }
/** * set the action text whether all caps * * @param snackbar the sanckbar * @param allCaps boolean allCaps,true or false */ publicstaticvoidsetSnackbarActionTextAllCaps(Snackbar snackbar, boolean allCaps){ View view = snackbar.getView(); TextView textView = (TextView) view.findViewById(R.id.snackbar_action); textView.setAllCaps(allCaps); }