Android Snackbar TextAlignment in Center
tv.setGravity(Gravity.CENTER_HORIZONTAL);
EDIT
The appearance of Snackbar
was changed in Support
library v23 so the correct answer now is:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
} else {
tv.setGravity(Gravity.CENTER_HORIZONTAL);
}
Try this:
// make snackbar
Snackbar mSnackbar = Snackbar.make(view, R.string.intro_snackbar, Snackbar.LENGTH_LONG);
// get snackbar view
View mView = mSnackbar.getView();
// get textview inside snackbar view
TextView mTextView = (TextView) mView.findViewById(android.support.design.R.id.snackbar_text);
// set text to center
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
mTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
else
mTextView.setGravity(Gravity.CENTER_HORIZONTAL);
// show the snackbar
mSnackbar.show();