无法在webView中使用预览相机

时间:2017-05-19 03:35:38

标签: android ionic-framework webview camera cordova-plugins

我的应用使用webView。但是,它无法预览相机,因为webView覆盖在Android应用上的相机上。它显示白色/空白屏幕,但我可以拍照。

enter image description here

  1. 我尝试设置背景透明webView。但它没有用。
  2. 我尝试过#34;带到前面"用相机。但它没有用。
  3. 我尝试将padding和margin设置为0.但它不起作用。
  4. 我尝试使用webView设置View.INVISIBLE它的相机可以显示预览,但我想显示一个按钮从webView拍照。 (它没有显示"拍照"按钮)。
  5. 我尝试调整大小(使用setLayoutParams)webview for show camera。我可以拍照但大小的webView变形。我不想让webView变形。我认为我们可以裁剪webView吗?
  6. enter image description here

    PS。 webView是CordovaWebView,Camera使用FrameLayout。

    cordova.getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {
    
    
        //create or update the layout params for the container view
        FrameLayout containerView = (FrameLayout)cordova.getActivity().findViewById(containerViewId);
        if(containerView == null){
          containerView = new FrameLayout(cordova.getActivity().getApplicationContext());
          containerView.setId(containerViewId);
    
          FrameLayout.LayoutParams containerLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
          cordova.getActivity().addContentView(containerView, containerLayoutParams);
        }
        //display camera bellow the webview
        if(toBack){
          webView.getView().setBackgroundColor(0x00000000);
          ((ViewGroup)webView.getView()).bringToFront();
        }else{
          //set camera back to front
          containerView.setAlpha(opacity);
          containerView.bringToFront();
        }
    
        //add the fragment to the container
        FragmentManager fragmentManager = cordova.getActivity().getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(containerView.getId(), fragment);
        fragmentTransaction.commit();
    
        cb.success("Camera started");
      }
    });
    

0 个答案:

没有答案
相关问题