我可以使用Xamarin.Android在文本视图中显示来自html的图像吗?

时间:2016-05-07 22:07:17

标签: android html image xamarin textview

我正在尝试使用Xamarin.Android在文本视图中显示html中的图像。 我已设法显示HTML但无法显示图片。 欢迎任何想法。

   Epub epub = new Epub(Android.OS.Environment.ExternalStorageDirectory.Path + "/Download/testBook.epub");

            //Get book title (Every epub file can have multiple titles)
            string title = epub.Title[0];

            //Get book authors (Every epub file can have multiple authors)
            string author = epub.Creator[0];

            //Get all book content as plain text
            string plainText = epub.GetContentAsPlainText();

            //Get all book content as html text
            string htmlText = epub.GetContentAsHtml();

            //Get some part of book content
            ContentData contentData = epub.Content[0] as ContentData;

            //Get Table Of Contents (TOC)
            List<NavPoint> navPoints = epub.TOC;

            String text = String.Format("<!DOCTYPE html PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<HTML>\n   <HEAD>\n      <TITLE>\n         A Small Hello \n      </TITLE>\n   </HEAD>\n<BODY>\n   <H1>Hi</H1>\n   <P style=\"color: red\">This is very minimal \"hello world\" HTML document.</P> \n</BODY>\n</HTML>");

            ePubEditText.CustomSelectionActionModeCallback = new CustomSelectionMenu(this);

            ePubEditText.TextFormatted = Html.FromHtml(htmlText);

1 个答案:

答案 0 :(得分:0)

Android TextView并非旨在显示此类内容。

如果您将TextView替换为WebView,则可以从字符串中加载“浏览器”中的内容,应用程序中捆绑的本地页面,当然还有远程网页:

String text = String.Format("<!DOCTYPE html PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<HTML>\n   <HEAD>\n      <TITLE>\n         A Small Hello \n      </TITLE>\n   </HEAD>\n<BODY>\n   <H1>Hi</H1>\n   <P style=\"color: red\">This is very minimal \"hello world\" HTML document.</P> \n</BODY>\n</HTML>");
var webViewString = FindViewById<WebView>(Resource.Id.webViewString);
webViewString.LoadData(text, "text/html", null);

var webViewLocalPage = FindViewById<WebView>(Resource.Id.webViewLocalPage);
webViewLocalPage.LoadUrl("file:///android_asset/HTML/index.html");

enter image description here

Xamarin:Load Local Content