从字符串改变的Andr​​oid TextView的颜色 [英] change android textview color from a string

查看:92
本文介绍了从字符串改变的Andr​​oid TextView的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿我创建一个机器人的TextView其中包含来自JSON ..
这是不错,但我想改变文本视图的一部分的颜色..不知道如何

Hey i am creating a android textview which contains come from json.. It is fine but i want to change color of the part of the text view.. dont know how

这是我的细节 -

JSONArray jArray= new JSONArray(result);

for(int i=0; i<jArray.length();i++)
{
JSONObject getjson=jArray.getJSONObject(i);

s= "Title: "            +getjson.getString("tender_title")+
   "\n\nTender id: "    +getjson.getString("tender_id")+
   "\n\nReference no:\n"+getjson.getString("tender_reference_no")+
   "\n\nQuantity: "     +getjson.getString("tender_item_details_quantity");

}

TextView txt=(TextView) findViewById(R.id.textView1);
txt.setText(s); 

在上面的code是fine..that设置文本视图中的所有价值,但我想改变的标题,投标ID,量的颜色等等。从上面的字符串的取值请帮忙

On the above code is fine..that sets all the value in the text view but i want to change the color of "Title" ,"Tender id", "Quantity" etc.. from above string s please help

推荐答案

您可以设置文本为html:

You can set the text as html:

txt.setText(Html.fromHtml("your <font color='#FF0000'>content</font>");

这篇关于从字符串改变的Andr​​oid TextView的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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