How to align message textview to the center in snackbar?

不羁岁月 提交于 2019-12-08 02:41:27

问题


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


回答1:


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



回答2:


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

snackTextView.setGravity(Gravity.CENTER_HORIZONTAL);   
snackTextView.setTextAlignment(Gravity.CENTER_HORIZONTAL);


来源:https://stackoverflow.com/questions/32694059/how-to-align-message-textview-to-the-center-in-snackbar

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