0

I am trying to use HTML in an AlertDialog .message() however it doesn't seem to use the HTML formatting.

from strings.xml

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

from my AlertDialog

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

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

Anyone know what might be causing this?

Thanks!

Rob
  • 1,162
  • 2
  • 18
  • 43

2 Answers2

1

You cant actually use tag in string.xml of android upon getting the string tag wont be retrieve only the string that was wrap in it because they are not supported, but you can still wrap then in <![CDATA[]]> to convert the tag into string so by the time you get the string you'll get the tag as well.

sample:

<string name="whatsnew"> <![CDATA[<b>What\'s New:</b>]]>
                            Transaction Screen:</string>
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
  • That seems to work for the most part, however, doesn't seem to recognize
    • tags. Any idea why?
    – Rob Aug 06 '14 at 18:23
  • @Rob android does not support all the HTML tag specially
    • . this post has all the existing html tag http://stackoverflow.com/questions/3150400/html-list-tag-not-working-in-android-textview-what-can-i-do
    – Rod_Algonquin Aug 06 '14 at 18:24
  • Thanks, just came across that same one myself. Appreciate your help! – Rob Aug 06 '14 at 18:25
0

If someone wants a different approach I just used escape sequences in line, for example:

<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>

Where:

&lt; = <

&gt; = >

Brian Reinhold
  • 2,313
  • 3
  • 27
  • 46