您的位置:首页 > 移动开发 > Android开发

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

2013-07-22 15:34 525 查看
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"><b><u>bold, underline </u></b></string>

在程序里引用:

Html.fromHtml(getResources().getString(R.string.myHeadStr));

效果图

android string html标签用法

<a href="http://www.chendw.cn/wp-content/uploads/2011/12/20111221160111.png" class="cboxElement" rel="example4" 606"="" style="text-decoration: none; color: rgb(1, 150, 227);">


string.xml代码

Code ViewCopyPrint

<string name="test"><Data><![CDATA[ <b><font color="#ff0000">ABC</font></b> ]]></Data></string>

java代码:

Code ViewCopyPrint

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.text.Html;

public class testActivity extends Activity {

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

AlertDialog.Builder dialog = new AlertDialog.Builder(testActivity.this);

dialog.setTitle("测试HTML标签").setMessage(Html.fromHtml(getString(R.string.test))).setPositiveButton(getString(R.string.btn_confirm), new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}

}).create().show();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: