Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align message textview to the center in snackbar?

How to align message textview to the center Horizontally in snackbar in android?

like image 969
Sudhir Sinha Avatar asked Sep 05 '25 15:09

Sudhir Sinha


1 Answers

Below is a sample, for making the Snackbar Text center horizontal

Snackbar snackbar = Snackbar.make(findViewById(R.id.coordinatorLayout), "Hello", Snackbar.LENGTH_SHORT);
snackbar.show();
View view = snackbar.getView();
TextView txtv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
txtv.setGravity(Gravity.CENTER_HORIZONTAL);

If you are using androidX

then replace the textview id com.google.android.material.R.id.snackbar_text

like image 112
Nigam Patro Avatar answered Sep 10 '25 11:09

Nigam Patro