在string.xml中格式化HTML标记?

时间:2014-11-28 17:50:44

标签: android android-layout textview

我尝试在string.xml中格式化一些HTML标记以在TextView中使用。 当像<p align="justify">this is my test using HTML in string.xml</p>这样的格式不起作用时,在TextView中文本不会尊重此标记。

我该怎么做?

我正在尝试这个。

//activity
TextView txtView = (TextView)findViewById(R.id.apresentation);
txtView.setText(Html.fromHtml(getString(R.string.apresentation)));

//string.xml
<string name="apresentacao">
    <![CDATA[
        <p align="justify">
            The battle of justice was making to who knows learn Lawyer 
            of some way to entertaining and join with your friends.
            The user can begin a Battle Justice and test your wisdom                
        <p>         

        <span>There's 3 arenas</span>
        <ul type="circle">
            <li>Beginner</li>
            <li>Carrier</li>
            <li>Battle Justice</li>             
        </ul>
    ]]>
</string>

1 个答案:

答案 0 :(得分:0)

String text = "<html><body style=\"text-align:justify\"> %s </body></Html>";
String data ="Hello World"
String txt=String.format(text, data);
Spanned result = Html.fromHtml(txt);
txtview.setText(result);

你可以尝试这种希望。