Android:在警报对话框中设置字体格式
我有两个问题
1)有谁知道如何将样式或格式应用于警报对话框。我目前使用 Builder builder = new AlertDialog.Builder(this); 并使用 setMessage() 方法来设置内容。
2)我还想知道如何更改linkify创建的链接的颜色。我不想要默认的蓝色。
I have two questions
1) Does anyone know, how to apply styles or formatting to alert dialog. I currently use Builder builder = new AlertDialog.Builder(this);
And use setMessage()
method to set the content.
2) Also I would like to know how to change the color of the links created by linkify. I don't want the default blue color.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Q1.您必须膨胀或自定义并创建样式并应用于 AlertDialog
以下是如何膨胀布局并将其应用于 AlertDialog
定义您指定的布局中所需的所有格式和样式。
您可以使用膨胀视图(即 Q2)访问布局中定义的特定文本视图
。
android:textColorLink="#FF00FF"
可用于指定链接的颜色。编辑:
保存为 res/layout/link.xml 的示例布局:
在 onCreate() 中或在您想要调用 AlertDialog 的位置或时间,
将
this
替换为上下文对象(如果您愿意)从其他方法调用。Q1. You have to inflate or customize and create a style and apply to AlertDialog
Heres how you inflate a layout and apply it to AlertDialog
define all the formatting and styles required in the layout you specified.
You can access specific textview defined in the layout using inflated View i.e.
Q2.
android:textColorLink="#FF00FF"
can be used to specify color of link.EDIT:
Sample layout saved as res/layout/link.xml:
In your onCreate() or where or whenever you want to call AlertDialog
replace
this
with context object if you are calling from some other method.您可以使用以下代码通过从默认警报对话框中提取 TextView 来更改字体和文本颜色:
you can use following code to change typeface and Text color by extracting TextView from default alertDialog: