Home  >  Article  >  Web Front-end  >  在字符串资源文件中添加HTML元素,直接使用字符串资源,HTML元素没起作用的解决办法_html/css_WEB-ITnose

在字符串资源文件中添加HTML元素,直接使用字符串资源,HTML元素没起作用的解决办法_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:38:241154browse

escape  html  in string resource 

 一、 需求描述

         给TextView赋值res资源库中的字符串资源,注意这里是一个string资源,要实现下面的效果

         “未绑定手机号 ? 绑定” ,最后面的俩个字要变红。

二、 实现方法

        思路如下,给绑定两个字用做处理。   

   <string> 未绑定手机号? <font color="#0f9afc">绑定</font></string>
    

三、问题描述

      如上操作,使用下面代码,不能实现我想要的效果。

   textview.setText(Html.fromHtml(getString(R.string.test_string)));


四、解决办法

     在Google上找到了一种解决办法,连接分享给大家      

   <a target="_blank" href="http://www.grokkingandroid.com/android-quick-tip-formatting-text-with-html-fromhtml/">点击打开链接</a>

 修改后的代码如下:

   <string name="test_string">绑定]]></string>


五、总结

       产品们的需求各种情况都有,能方便点做,咱就方便点做,这个小知识点,希望能帮到大家,回家吃饭了,晚上找个电影看看,祝大家晚餐愉快。




          

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn