更改特定文本的颜色警报对话框 [英] Changing color of particular text in Alert Dialog

查看:227
本文介绍了更改特定文本的颜色警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个xml中,我有以下几点:

 约翰:你好吗?
玛丽:我fine.How你。
约翰:今天你有什么打算?

我从XML获取这些值。现在我需要用约翰,玛丽文本粗体不同的颜色。同时,我需要改变警报窗口的背景颜色。

我使用这个警告对话框:

  AlertDialog.Builder BU =新AlertDialog.Builder(本);
bu.setMessage(。+((节点)textFNListU.item(0))getNodeValue()修剪()代替($,\\ n));
bu.setCancelable(真);
bu.setPositiveButton(OK,新DialogInterface.OnClickListener(){
        @覆盖
        公共无效的onClick(DialogInterface对话,诠释的id){
        // TODO自动生成方法存根
                    dialog.cancel();
                        }
                        });
                。bu.create()显示();

((节点)textFNListU.item(0))。getNodeValue()。修剪()) ----这个我从XML获得<值/ p>

请帮忙。


解决方案

您可以更改,如文本颜色:
例如:字符串为约翰:你好吗?然后,

  builder.setMessage(Html.fromHtml(&LT;字体颜色=#FF0000&GT;&LT; B&GT;约翰:&LT; / B&GT;&LT; / FONT&gt;中+ 你好吗?))

它会给你约翰:以红色和白色的text.You剩余的文本也可以改变根据自己的需要

对于自定义对话框,您可以参考<一个href=\"http://blog.androgames.net/10/custom-android-dialog/\">http://blog.androgames.net/10/custom-android-dialog/

hi guys i have an xml in that i am having the following :

John:How are you?
Mary:I am fine.How about you.
John:what is your plan today?

I am fetching these values from xml .Now i need the John,Mary text with BOLD and in different color. and also i need to change the background color of alert window.

this the alert dialog i am using:

AlertDialog.Builder bu = new AlertDialog.Builder(this);
bu.setMessage(""+((Node) textFNListU.item(0)).getNodeValue().trim().replace("$","\n"));
bu.setCancelable(true);
bu.setPositiveButton("OK",new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
        // TODO Auto-generated method stub
                    dialog.cancel();
                        }
                        });
                bu.create().show();

((Node) textFNListU.item(0)).getNodeValue().trim()) ----this the value i am getting from xml

please help.

解决方案

You can change color of text like: for example: string is "John:How are you?" then,

builder.setMessage(Html.fromHtml("<font color='#FF0000'><b>John:</b></font>"+"How are you?"))

It will give you John: in red color and remaining text in white colored text.You can change that also as per your need.

For customized dialog,you can refer http://blog.androgames.net/10/custom-android-dialog/

这篇关于更改特定文本的颜色警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆