简体   繁体   English

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

[英]How to set formatted html text in a textview from String.xml?

I can able to getting text but not all tags works properly.The bold and italic tag not working where break tag works. 我可以获取文本,但并非所有标签都可以正常工作。粗体和斜体标签在break标签起作用的地方不起作用。

My String.xml is: 我的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>

And My code to set TextView text is: 我设置TextView文本的代码是:

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

Remove formatted="false" from 从中删除formatted="false"

  <string name="text_to_show" formatted="false">

or set it to true . 或将其设置为true

i have checked your code and try in my app, but its working fine. 我已经检查了您的代码并尝试在我的应用程序中运行,但工作正常。 may be there some android version issue or device issue. 可能存在一些android版本问题或设备问题。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM