弱龄寄事外,委怀在琴书。这篇文章主要讲述xamarin.form 使用WebView和APP交互相关的知识,希望能为你提供帮助。
< WebView Source="https://www.baidu.com"> < /WebView>
可以用后台代码和webview互动,例如webview.Eval("alert(‘hello‘)");
xamarin.form原生webview有很多bug,建议使用第三方的view控件HybirdWebView
如果要使用这个view,需要安装XLabs.Serialization.JSON,和XLabs.Forms
然后在ios中将appdelegate修改为
// The UIApplicationDelegate for the application. This class is responsible for launching the // User Interface of the application, as well as listening (and optionally responding) to // application events from iOS. [Register("AppDelegate")] public partial class AppDelegate : XLabs.Forms.XFormsApplicationDelegate { // // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { SetIoc(); global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); return base.FinishedLaunching(app, options); } private void SetIoc() { var resolverContainer = new SimpleContainer(); resolverContainer.Register< IJsonSerializer, JsonSerializer> (); Resolver.SetResolver(resolverContainer.GetResolver()); } }
在android中修改mainactive修改为
[Activity(Label = "App2", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : XFormsApplicationDroid { protected override void OnCreate(Bundle savedInstanceState) { //TabLayoutResource = Resource.Layout.Tabbar; //ToolbarResource = Resource.Layout.Toolbar; SetIoc(); base.OnCreate(savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); } private void SetIoc() { var resolverContainer= new SimpleContainer(); resolverContainer.Register< IJsonSerializer, JsonSerializer> (); Resolver.SetResolver(resolverContainer.GetResolver()); } }
LoadFinished事件加载完成事件
CallJsFunction("alert","你好");
在html中加入代码注册按钮回掉后台代码
function Callback(){ Native("datacallback","this is callback paramer"); }
然后在后台代码中加入
webView.RegisterCallback("datacallback",t=> {T就是参数});
【xamarin.form 使用WebView和APP交互】
推荐阅读
- 基于android的相关的管理系统的毕业设计代写
- qq天降红包怎样屏蔽?qq天降红包关闭图文详细教程
- QQ厘米秀一飞冲天卡获得图文详细教程
- QQ新春大礼包入口在啥地方?QQ新春大礼包活动地址列表
- qq公布表情大数据:12星座最爱啥QQ表情大公开
- 2017qq红包雨怎样玩?2017qq红包雨玩法介绍
- 微信面对面红包在啥地方?微信面对面红包入口介绍_微信
- 微信面对面红包怎样回收?微信面对面红包回收图文详细教程_微信
- 微信6.5.4新版本有哪些新技巧?_微信