我是靠谱客的博主 呆萌芒果,最近开发中收集的这篇文章主要介绍xamarin读取本地html,xamarin.android - How to load local HTML files in Xamarin Forms WebView - Stack Over...,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I intend to load local HTML files into a Xamarin Forms WebView.

I've added the HTML files to the assets/HTML folder, and its Build Action is set to AndroidAsset.

I've implemented the base URL finder interface:

public class BaseUrl_Android:IBaseUrl

{

public string Get()

{

return "file:///android_asset/";

}

}

I have tried to load the file from the using this in the shared portable code:

string baseUrl = DependencyService.Get().Get();

string url = baseUrl + "HTML/local.html";

myWebView.Source = url;

I also tried a custom WebViewRenderer, and used this code:

protected override void OnElementChanged(ElementChangedEventArgs e)

{

base.OnElementChanged(e);

if (e.OldElement == null)

{

// lets get a reference to the native control

var webView = (global::Android.Webkit.WebView)Control;

// do whatever you want to the WebView here!

webView.LoadUrl(DependencyService.Get().Get()+"HTML/local.html");

webView.SetWebViewClient(new MyWebViewClient());

}

With both solutions I get an error:

38brr.png

What else should I try?

最后

以上就是呆萌芒果为你收集整理的xamarin读取本地html,xamarin.android - How to load local HTML files in Xamarin Forms WebView - Stack Over...的全部内容,希望文章能够帮你解决xamarin读取本地html,xamarin.android - How to load local HTML files in Xamarin Forms WebView - Stack Over...所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部