Chathura Wijesinghe Chathura Wijesinghe - 5 months ago 222
Android Question

Android Snackbar TextAlignment in Center

enter image description here

How to change the Snackbar text alignment to center ? bellow code is not working

Snackbar snack = Snackbar.make(findViewById(android.R.id.content), intent.getStringExtra(KEY_ERROR_MESSAGE), Snackbar.LENGTH_LONG);
View view = snack.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.red_EC1C24));
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
snack.show();

Answer
tv.setGravity(Gravity.CENTER_HORIZONTAL);
Comments