Android里string.xml使用html标签的方法

Android里string.xml使用html标签的方法
2011年12月21日  ⁄ 编程技术 ⁄ 共 1107字 ⁄ 暂无评论 ⁄ 被围观 3,656 views+
方法1、使用 CDATA(推荐)
<string name="demoStr"><Data><![CDATA[ <b>ABC</b> ]]> </Data></string>
方法2、转义HTML标签
<string name="myHeadStr">&lt;b>&lt;u>bold, underline &lt;/u>&lt;/b></string>
在程序里引用:
Html.fromHtml(getResources().getString(R.string.myHeadStr));
效果图
android string html标签用法
<a href="https://i-blog.csdnimg.cn/blog_migrate/35171da9b1789b6851aa26e54925f566.png" class="cboxElement" rel="example4" 606"="" style="text-decoration: none; color: rgb(1, 150, 227);">
string.xml代码
Code    View Copy Print
  1. <string name="test"><Data><![CDATA[ <b><font color="#ff0000">ABC</font></b> ]]></Data></string>  

java代码:

Code    View Copy Print
  1. import android.app.Activity;   
  2. import android.app.AlertDialog;   
  3. import android.content.DialogInterface;   
  4. import android.os.Bundle;   
  5. import android.text.Html;   
  6.   
  7. public class testActivity extends Activity {   
  8.     public void onCreate(Bundle savedInstanceState) {   
  9.         super.onCreate(savedInstanceState);   
  10.         AlertDialog.Builder dialog = new AlertDialog.Builder(testActivity.this);   
  11.         dialog.setTitle("测试HTML标签").setMessage(Html.fromHtml(getString(R.string.test))).setPositiveButton(getString(R.string.btn_confirm), new DialogInterface.OnClickListener() {   
  12.             public void onClick(DialogInterface dialog, int which) {   
  13.   
  14.             }   
  15.         }).create().show();   
  16.     }   
  17. }   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值