AlertDialog更改字体的外观

AlertDialog更改字体的外观

本文介绍了AlertDialog更改字体的外观(大小,颜色,对齐)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的比赛里面我AlertDialog的属性,我目前这种方式构建的:

And if player clicked certain button, I'm showing this dialog with this way:

showDialog(DIALOG_INFO);

Everything works, but I decided to change look of font used in this dialog, with this way:

But code works only, if I put this code after showDialog(DIALOG_INFO); which means I have to create new object (TextView textView = ...) everytime I'm showing dialog, and my question is, can't I do it only once while creating dialog?

Thanks in advance.

解决方案

You can set your own contentView for AlertDialog:

.....
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = (ViewGroup) inflater.inflate(R.layout.YOUR_DIALOG_LAYOUT, null);
builder.setView(rootView);
.....

And markup your dialog layout in xml.

这篇关于AlertDialog更改字体的外观(大小,颜色,对齐)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 14:45