如何在String.xml中设置textview格式的html文本?

时间:2016-03-29 07:24:33

标签: android

我能够获取文本,但并非所有标签都能正常工作。粗体和斜体标签在break标签工作的地方不起作用。

我的String.xml是:

<resources>
<string name="app_name">MyAppTXT_PageSplit</string>
<string name="text_to_show" formatted="false">
    <![CDATA[
       <i><b>Forbes Leadership, 2015</b></i><br><br>
       Your Emotional Intelligence (EI) directly relates to your ability to lead people successfully. One of many studies correlating Executives’ EI scores with their company’s profitability demonstrated that those with higher EI capabilities were more likely to be highly profitable (Leadership & OD Journal ,2009)

       <br><br>LeaderShaper is a self-development tool for professionals to develop their Emotional Intelligence as a key step to becoming a better leader and enabling high performance. Focus on one set of competencies at a time and get some real practical advice on how to improve your EI through behavioural change.  You can repeat it to see how your scores improve.
       <br><br>Just enter your own ratings against each of the questions.  When you complete a section, click on the ADVICE button for practical advice to help you improve your EI.
       <br><br>Once you have completed the questionnaire, you can obtain a LeaderShaper Pro Report for £2.99, showing how your EI profile rates against each of the six recognised leadership styles.
       <br><br>
       <b>&#8226;</b>   &#160;&#160;&#160;&#160; Visionary, Coaching, Democratic, Affiliative, Pacesetting &amp; Commanding <br>
    ]]>
</string>

我设置TextView文本的代码是:

txt_show.setText(Html.fromHtml(getResources().getString(R.string.text_to_show)));

2 个答案:

答案 0 :(得分:0)

中删除formatted="false"
  <string name="text_to_show" formatted="false">

或将其设为true

答案 1 :(得分:0)

我已经检查了您的代码并尝试使用我的应用,但它的工作正常。 可能存在一些Android版本问题或设备问题。enter image description here