在AlertDialog消息中使用HTML

时间:2014-08-06 18:05:45

标签: android android-alertdialog

我正在尝试在AlertDialog .message()中使用HTML,但它似乎不使用HTML格式。

来自 strings.xml

<string name="whatsnew">
        <b>What\'s New:</b>
        Transaction Screen:
    </string>

来自我的AlertDialog

final String message = mActivity.getString(R.string.whatsnew);

AlertDialog.Builder builder = new AlertDialog.Builder(mActivity)
                            .setTitle(title)
                            .setMessage(Html.fromHtml(message))

任何人都知道可能导致这种情况的原因吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

你实际上不能在android的string.xml中使用标签获取字符串标签时不会只检索包含在其中的字符串,因为它们不受支持,但你仍然可以在<![CDATA[]]>中包装将标记转换为字符串,这样当你得到字符串时,你也会获得标记。

<强>样品:

<string name="whatsnew"> <![CDATA[<b>What\'s New:</b>]]>
                            Transaction Screen:</string>

答案 1 :(得分:0)

如果有人想要不同的方法,我只是在行中使用转义序列,例如:

<string name="permissions_location_11">&lt;p&gt;LOCATION PERMISSION: Needs to be granted in order for this app to use the Bluetooth LE scanner.
    The scanner is needed to discover BLE health devices and know what they are.&lt;/p&gt;
    &lt;p&gt;&lt;font color=\"red\"&gt;This app does NOT use location information or expose location information.&lt;/font&gt;
    Without this permission you will only be able to work with SPP and HDP devices.&lt;/p&gt;
    &lt;p&gt;READ CAREFULLY! In Android 11+ this process is much more difficult. You need to select \'Allow in settings\' and that will bring you to the settings menu
    where you need to select \'all the time\'. If you do not Android may kill the Bluetooth service if you bring another app into the foreground. When done press
    the back arrow to return to Health@Home.&lt;/p&gt;</string>

地点:

< = <

> = >