我正在编写一个带有自定义插件的Phonegap应用程序。此插件在其自己的SurfaceView上生成全屏动画背景(基本上是视频)(将其视为背景视频)。我想将常规的phonegap webview作为透明叠加层放在这个插件的顶部。我怎么能这样做?
我目前的代码:
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
final FrameLayout layout = (FrameLayout) webView.getView().getParent();
final Activity activity = cordova.getActivity();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
// here I insert the surface
// that I want to be placed behind the webview
activity.setContentView(R.layout.preview);
MySurfaceView myView = new MySurfaceView(activity);
FrameLayout preview = (FrameLayout) activity.findViewById(R.id.myview);
preview.addView(myView);
}
catch(Exception e) {
Log.e(CamCapture.TAG, "failed: " + e.getMessage());
}
}
});
}
这个问题与How can I overlay a native view on top of PhoneGap's CordovaWebView in Android?
相反答案 0 :(得分:2)
您可以通过在相对布局中将您的网页视图放在本机视图上并在网络视图上设置以下属性来实现此目的
wv.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
view.setBackgroundColor(ContextCompat.getColor(context, R.color.transparent));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
});
wv.setBackgroundResource(android.R.color.transparent);
它会使您的webview背景透明,您可以看到您的原生视图。