How to align message textview to the center in snackbar?

我与影子孤独终老i 提交于 2019-12-06 11:58:23

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);

Try to set both textAlignment and Gravity to the Gravity.CENTER_HORIZONTAL

snackTextView.setGravity(Gravity.CENTER_HORIZONTAL);   
snackTextView.setTextAlignment(Gravity.CENTER_HORIZONTAL);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!