简体   繁体   English

字体颜色android html

[英]font color android html

I am making a note application and want the user to be able to edit in rich text. 我正在做一个笔记应用程序,希望用户能够以富文本格式进行编辑。

The user writes the note, then it gets converted into html and saved into a database. 用户编写便笺,然后将其转换为html并保存到数据库中。

This way when it is retrieved from the database, it does not lose its rich text. 这样,从数据库中检索它时,它不会丢失其富文本格式。

Yet I am having a problem, if the user adds a color to their text and saves the note it converts it to html like this 但是我有一个问题,如果用户在文本中添加颜色并保存便笺,它将像这样转换为html

"<p><font color=#0000ff>user text</font></p>"

when retrieved from the database no text color shows up. 从数据库中检索时,没有显示文本颜色。 this is because android saves the html wrong. 这是因为android保存html错误。 In order for android to get color from html the letters need to be capitalized like this 为了使android从html获取颜色,需要像这样将字母大写

"<p><font color=#0000FF>user text</font></p>"

This confuses me because if android can only read it in caos why doesn't it convert it in that way. 这使我感到困惑,因为如果android仅能以caos的形式读取它,为什么它不会以这种方式进行转换。

How do I get it so when this code runs 运行此代码后如何获得它

    //--save to string--//
    Editable e = noteContent.getText();
    String s2 = Html.toHtml(e);

    Spanned s3 = Html.fromHtml(s2);
    classes.setText(s3);

to save the text color to the caps. 将文本颜色保存到大写。 so when it is retrieved form the database the text color shows up. 因此,当从数据库中检索文本时,将显示文本颜色。

Thanks, 谢谢,

Jordan 约旦

Make sure your RGB value is CAPITALIZED. 确保您的RGB值是大写的。 Try to use: 尝试使用:

Html.fromHtml("<![CDATA[<font color='#145A14'>text</font>]]>");

Hope this help! 希望有帮助!

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

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