Android 将HTML文本转换为标记
我有一个html文本,我们从富文本编辑器得到,我需要将富文本转换成标记文本 例如: 富文本返回Android 将HTML文本转换为标记,android,github-flavored-markdown,multimarkdown,Android,Github Flavored Markdown,Multimarkdown,我有一个html文本,我们从富文本编辑器得到,我需要将富文本转换成标记文本 例如: 富文本返回 <b> strong </b> to **strong** strong 到 **强壮的** 有人能帮我安卓吗?你也可以从HTML字符串加载: String summary = "<html><body>You scored <b>192</b> points.</body></html>"
<b> strong </b>
to
**strong**
strong
到
**强壮的**
有人能帮我安卓吗?你也可以从HTML字符串加载:
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>", Html.FROM_HTML_MODE_COMPACT));
String summary=“你得了192分。”;
loadData(摘要,“text/html”,空);
(或)
例如( String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>", Html.FROM_HTML_MODE_COMPACT));
myTextView.setText(Html.fromHtml(“Title
此处的说明”);
例如(>=Android牛轧糖):
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>", Html.FROM_HTML_MODE_COMPACT));
myTextView.setText(Html.fromHtml(“Title
Description here”,Html.FROM\u Html\u MODE\u COMPACT));
我的建议是最好使用webview,因为表标记和一些
文本视图中没有显示更多标记
尝试此代码
TextView textView = (TextView) findViewById(R.id.textView);
String htmlText = "<b> strong </b>";
textView.setText(Html.fromHtml(htmlText).toString());
TextView TextView=(TextView)findViewById(R.id.TextView);
字符串htmlText=“strong”;
textView.setText(Html.fromHtml(htmlText.toString());
您可以使用java android将html转换为标记。
下面是在Android中使用的示例
void test(String theHTML)
{
File xsltFile = new File("mardownXSLT.xslt");
Source xmlSource = new StreamSource(new StringReader(theHTML));
Source xsltSource = new StreamSource(xsltFile);
TransformerFactory transFact =
TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
StringWriter result = new StringWriter();
trans.transform(xmlSource, new StreamResult(result));
}
您可以使用这个库(页面上的下载已被破坏,但也可以在上获得),它还支持GitHub和多标记风格的标记。代码可以如下所示:
public static void main(String[] args) {
final String html = "<b>Foo</b>";
final Remark remark = new com.overzealous.remark.Remark(com.overzealous.remark.Options.github()); // or Options.markdown() or Options.multiMarkdown()
remark.setCleanedHtmlEchoed(false);
System.out.println(remark.convert(html));
}
publicstaticvoidmain(字符串[]args){
最后一个字符串html=“Foo”;
final Remark Remark=new com.overzealious.Remark.Remark(com.overzealious.Remark.Options.github());//或Options.markdown()或Options.multiMarkdown()
备注:setCleanedHtmlEchoed(假);
System.out.println(remark.convert(html));
}
输出:
**Foo**
请阅读上面的问题和答案,我要求html文本进行标记而不是呈现它。@Anburesult.toString()
是转换后的字符串