¿Cómo puedo superponer una vista nativa encima de CordovaWebView de PhoneGap en Android?

Estoy construyendo un plugin de phonegap que necesita hacer una vista de interfaz de usuario nativa encima de la WebView que proporciona PhoneGap. En iOS esto es muy simple, solo crea la vista y añádela al scrollView de PhoneGap's webView. Esto hará que el control se encuentre en la parte superior del webView y le permita desplazarse con el contenido HTML (tenga en cuenta que este ejemplo utiliza un UIButton, pero lo aplicaré a un control de interfaz de usuario personalizado):

-(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]; } 

He intentado hacer algo aproximadamente equivalente en Android, pero no he tenido éxito. Aquí está mi intento más reciente:

 @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { System.out.println(String.format("%s action called", action)); if ("echo".equals(action)) { String message = args.optString(0); this.echo(message, callbackContext); return true; } else if ("createNativeControl".equals(action)) { this.createNativeControl(callbackContext); return true; } return false; } private void createNativeControl(CallbackContext callbackContext) { // Find the frame layout parent and place the control on top - theoretically // this should appear on TOP of the webView content since the TextView child is // added later FrameLayout frameLayout = (FrameLayout) webView.getParent().getParent(); TextView view = new TextView(frameLayout.getContext()); view.setText("Hello, Android!"); view.setVisibility(View.VISIBLE); frameLayout.addView(view, 100,100); callbackContext.success(); } 

¿Cómo puedo lograr esto en Android?

Con Cordova Android 4.0.2, pude añadir una vista en la parte superior de la webview, así:

 public class HVWMaps extends CordovaPlugin { @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { FrameLayout layout = (FrameLayout) webView.getView().getParent(); TextView textView = new TextView(layout.getContext()); textView.setBackgroundColor(Color.BLUE); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(500, 500); params.setMargins(100, 100, 100, 100); textView.setLayoutParams(params); layout.addView(textView); } } 

Parece que la interfaz para CordovaWebView ha cambiado recientemente, por lo que esto puede no funcionar con versiones anteriores. Para este ejemplo, también necesitará agregar <param name="onload" value="true" /> a la función en su plugin.xml para que initialize(..) se llame:

 <platform name="android"> <config-file target="res/xml/config.xml" parent="/*"> <feature name="YourPlugin" > <param name="android-package" value="com.your.plugin"/> <param name="onload" value="true" /> </feature> </config-file> </platform> 

Esto no se desplaza con la webview como mencionaste iOS, pero para mi proyecto no lo necesitaba.

¿Has tratado de ver el orden de tus puntos de vista? Tal vez está superpuesto en tu webview

// ocultar la vista web
//webview.setVisibility(View.GONE); // para probar si la nueva vista aparece
webview.setZOrderOnTop (true);

// muestra la nueva vista myView.setVisibility (View.VISIBLE);

myView.bringToFront ();

Voy a asumir que está 100% seguro de esta línea obtener un padre válido que se puede agregar una vista.

FrameLayout frameLayout = (FrameLayout) webView.getParent (). GetParent ();

  • Phonegap - Trae de fondo a primer plano
  • Error en la aplicación Phonegap: módulo no capturado cordova / plugin_list ya definido
  • La aplicación Ionic / Cordova no recibe notificación push en el fondo
  • No se pudo encontrar com.parse.bolts: bolts-android: 1.1.2. En el proyecto de la brecha del teléfono (estudio del androide)?
  • Cómo llamar a la función en el marco iónico + angularjs?
  • Uncaught TypeError: Object # <Object> no tiene ningún método 'exec' en el archivo: ///android_asset/www/index.html
  • La generación de Gradle falló cuando el soporte de importación-v4-22.0.0
  • Cómo seleccionar el video de la galería en el teléfono?
  • PhoneGap 3 plugin: exec () llamada a plugin desconocido "..."
  • Phonegap Build CLI-5.2.0 Descargar y cerrar desde dentro de la aplicación Web
  • PhoneGap / Android, abra ChildBrowser desde .shouldOverrideUrlLoading ()
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.