【问题标题】:Remove a Fragment view and go back to Cordova Webview删除片段视图并返回 Cordova Webview
【发布时间】:2015-08-11 14:25:40
【问题描述】:

我正在创建一个基于 Android Camera2Video 示例 http://developer.android.com/samples/Camera2Video/index.html 的 Cordova 插件

我有显示和录制视频的相机叠加层。但是,当我想删除视图时,它只会显示黑屏。

添加视图的代码:

Fragment fragment = Camera2VideoFragment.newInstance(cordova, callback);
cordova.getActivity().setContentView(resources.getIdentifier("activity_camera", "layout", packageName));
cordova.getActivity().getFragmentManager().beginTransaction().replace(resources.getIdentifier("container", "id", packageName), fragment).commit();

移除视图的代码:

Fragment fragment = cordova.getActivity().getFragmentManager().findFragmentById(resources.getIdentifier("container", "id", packageName));
cordova.getActivity().getFragmentManager().beginTransaction().remove(fragment).commit();

如何移除片段并返回到常规 WebView?

到目前为止,我的插件代码在这里: https://github.com/kmturley/cordova-plugin-media-custom

【问题讨论】:

    标签: java android cordova android-fragments webview


    【解决方案1】:

    好的,所以我设法使用以下代码解决了它:

    添加视图:

    cordova.getActivity().setContentView(resources.getIdentifier("activity_camera", "layout", packageName));
    cordova.getActivity().getFragmentManager().beginTransaction().replace(resources.getIdentifier("container", "id", packageName), Camera2VideoFragment.newInstance(cordova, callback)).commit();
    

    移除视图:

    Fragment fragment = cordova.getActivity().getFragmentManager().findFragmentById(resources.getIdentifier("container", "id", packageName));
    cordova.getActivity().getFragmentManager().beginTransaction().remove(fragment).commit();
    cordova.getActivity().setContentView(getView());
    

    我从 cordova-plugin-splashscreen 存储库复制了 getView 函数:https://github.com/apache/cordova-plugin-splashscreen/blob/master/src/android/SplashScreen.java

    private View getView() {
        try {
            return (View)webView.getClass().getMethod("getView").invoke(webView);
        } catch (Exception e) {
            return (View)webView;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多