我正在构建一个phonegap插件,需要在PhoneGap提供的WebView上呈现本机UI视图.在iOS中,这非常简单,只需创建视图并将其添加到PhoneGap的webView的scrollView中.这将在webView上呈现控件并允许它与HTML内容一起滚动(请注意,此示例使用UIButton,但我将其应用于自定义UI控件):
-(void)createNativeControl:(CDVInvokedUrlCommand *)command
{
NSDictionary* options = [command.arguments objectAtIndex:0];
NSNumber* x = [options objectForKey:@"x"];
NSNumber* y = [options objectForKey:@"y"];
NSNumber* width = [options objectForKey:@"width"];
NSNumber* height = [options objectForKey:@"height"];
CGRect rect = CGRectMake([x floatValue], [y floatValue], [width floatValue], [height floatValue]);
self._nativeControl = [UIButton buttonWithType:UIButtonTypeSystem];
self._nativeControl.frame = rect;
[self._nativeControl addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self._nativeControl setTitle:@"Click me" forState:UIControlStateNormal];
[self.webView.scrollView addSubview:self._nativeControl];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackID];
}
Run Code Online (Sandbox Code Playgroud)
我尝试过在Android中大致相同的东西,但没有成功.这是我最近的尝试:
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
System.out.println(String.format("%s …Run Code Online (Sandbox Code Playgroud)