如何将消息的textview对齐小吃栏的中心? [英] How to align message textview to the center in snackbar?
本文介绍了如何将消息的textview对齐小吃栏的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Android的快餐栏中将消息的textview水平对齐到中心?
How to align message textview to the center Horizontally in snackbar in android?
推荐答案
下面是一个示例,用于使Snackbar文本中心保持水平
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);
如果您使用的是androidX
If you are using androidX
然后替换textview
id com.google.android.material.R.id.snackbar_text
这篇关于如何将消息的textview对齐小吃栏的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文