中心中的Android Snackbar TextAlignment [英] Android Snackbar TextAlignment in Center
本文介绍了中心中的Android Snackbar TextAlignment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将Snackbar文本对齐方式更改为居中?波纹管代码不起作用
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();
推荐答案
tv.setGravity(Gravity.CENTER_HORIZONTAL);
编辑
Support
库v23中 Snackbar
的外观已更改,因此现在的正确答案是:
The appearance of Snackbar
was changed in Support
library v23 so the correct answer now is:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
} else {
tv.setGravity(Gravity.CENTER_HORIZONTAL);
}
这篇关于中心中的Android Snackbar TextAlignment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文