开发者

Unordered list styling with HTML markup

In the link String Resource I came to know that Android supports only Bold, Italic and Underline styling with HTML markup, and I have seen some Application that displays Unordered list inside the AlertDialog, so tried to implement that in my application as

in my String.xml, I've given

<String name="unorderedlist">Different Types &lt;ul> &lt;li>T ype 1 &lt;/li> &lt;li> Type 2 &lt;/li> &lt;/ul> 开发者_开发百科</String>

in my activity, I tried to display it inside my AlertDialog as follows

String formatedString=String.format(getResources().getString(R.string.unorderedlist), "");
myAlertDialogBuilder.setMessage(Html.fromHtml(formatedString));

Its not working, So is there any other way to do this, give me some guidance. Thanks in Advance.


I saved the file that should be displayed as HTML page an HTML file inside the assets folder and designed a Custom Dialog box with a WebView and in the Java file I loaded the HTML file from the local resource and displayed it inside WebView.


Bulleted list can be simply created by using the <ul> and <li> tags in the string resource.

DO NOT USE setText(Html.fromHtml(string)) to set the string in code! Just set the string normally in xml or by using setText(string).

E.g:

strings.xml file

<string name="str1"><ul> <li><i>first</i> item</li> <li>item 2</li> </ul></string>


layout.xml file

    <TextView
        android:text="@string/str1"
    />


It will produce the following result:

  • first item
  • item 2


Following tags are supported like this (directly embedded in the string resource):

  • <a> (supports attributes "href")
  • <annotation>
  • <b>
  • <big>
  • <font> (supports attributes "height", "size", "fgcolor" and "bicolor", as integers)
  • <i>
  • <li>
  • <marquee>
  • <small>
  • <strike>
  • <sub>
  • <sup>
  • <tt>
  • <u>


Try looking in APIDemos > App> Alert Dialog Samples. You will find various examples on how to use Alert Dialogs.

For the code:

it is inside com.example.android.apis.app package -> AlertDialogSamples.java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜