概述
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:
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...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复