android集成多个5+webview

5+webview只需要集成一次时,按照Dcloud官方文档集成。

如果需要集成多次,在之后的activity中只需要调用SDK.creatWebview方法,创建出webview,然后添加到布局文件中即可

final FrameLayout rootView = (FrameLayout) findViewById(R.id.frameLayout);	//使用自己的布局
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        webview.onRootViewGlobalLayout(rootView);
    }
});
webview = SDK.createWebview(this, url, new IWebviewStateListener() {
    @Override
    public Object onCallBack(int i, Object pArgs) {
        switch (i) {
            case IWebviewStateListener.ON_WEBVIEW_READY:
                View view = LayoutInflater.from(App.getcontext()).inflate(R.layout.dcloud_loadingview, null);
                rootView.addView(view);
                ((IWebview) pArgs).obtainFrameView().obtainMainView().setVisibility(View.INVISIBLE);
                SDK.attach(rootView, ((IWebview) pArgs));
                break;
            case IWebviewStateListener.ON_PAGE_STARTED:
                break;
            case IWebviewStateListener.ON_PROGRESS_CHANGED:
                break;
            case IWebviewStateListener.ON_PAGE_FINISHED:
                webview.obtainFrameView().obtainMainView().setVisibility(View.VISIBLE);
                break;
        }
        return true;
    }
});

你可能感兴趣的:(android集成多个5+webview)