【问题标题】:Xamarin forms: Display the title, subtitle and numbered points in UI from HTML dataXamarin 表单:根据 HTML 数据在 UI 中显示标题、副标题和编号点
【发布时间】:2019-10-14 07:22:23
【问题描述】:

我使用HtmlAgilityPack 将 HTML 数据转换为字符串。但我需要再次格式化文本,如下所示。

here 上添加的示例 HTML 数据。

我的文本有标题、副标题和编号点。那么如何像上面截图那样改变数据呢?

【问题讨论】:

标签: html string xamarin.forms


【解决方案1】:

你可以使用插件HtmlLabelPlugin

从 nuget 将其安装在每个 Xamarin.Forms 项目中。

iOS:AppDelegate.cs

HtmlLabelRenderer.Initialize();
global::Xamarin.Forms.Forms.Init();

Android:MainActivity.cs

HtmlLabelRenderer.Initialize();
global::Xamarin.Forms.Forms.Init(this, bundle);

在xml中

xmlns:htmlLabel="clr-namespace:LabelHtml.Forms.Plugin.Abstractions;assembly=HtmlLabel.Forms.Plugin"
<htmlLabel:HtmlLabel Text="{Binding HtmlString}"/>

【讨论】:

  • 仍然,编号点未正确对齐,我需要编号点左对齐。那可能吗?当前截图:drive.google.com/open?id=1yHEsPOjiG3pu-kW-SbYGYTn9TrDOZtQu
  • 我认为是因为该插件不支持html中的标签方
  • 如果您需要在 Android 或 iOS 中自定义某些内容,您可以使用内联 CSS,例如:&lt;span style="color: red"&gt;1.&lt;/span&gt;
  • 为什么要在标签中显示?这不是一个明智的方法。您可以将其显示在 webview 或 pdf 中。
  • 由于css样式,有些格式会显示,但是在label上显示时就不行了。
【解决方案2】:

将 TextType 添加到 Label 并在 Text 属性上绑定 html 代码

<Label x:Name="HtmlLbl" TextType="Html">

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-12-06
  • 2022-11-16
  • 1970-01-01
  • 2021-03-31
  • 2019-01-22
  • 1970-01-01
  • 1970-01-01
  • 2016-04-18
相关资源
最近更新 更多