在DialogFragment中预加载webview

时间:2017-07-20 01:26:39

标签: android android-webview android-dialogfragment

DialogFragmentwebview

每次显示DialogFragment,webview都需要一些时间来加载webview,在网页加载完成之前,webview将显示背景颜色。这会影响用户体验。所以我想用一些方法预加载webview。但真的告诉我,m_webviewDialog.show会启动两个函数onCreateDialogonCreateView。那么有没有让webview预加载然后加入onCreateView fucnion?

主要活动显示代码:

     public void showWebviewDialog()
        {

            FragmentManager fragmentManager=getFragmentManager();
            if(m_webviewDialog!=null&&m_webviewDialog.isAdded())
            {
                m_webviewDialog.getDialog().show();
            }
            else {
                m_webviewDialog=mcWebViewDialog.newInstance();
                m_webviewDialog.set_loadurl("file:///android_asset/input.html");
                m_webviewDialog.show(fragmentManager,"mcWebDialog");
            }


        }

DialogFragment代码:

     WebView m_webView;//WebView component
     String m_loadurl;
static mcWebViewDialog newInstance()
    {
        mcWebViewDialog f=new mcWebViewDialog();

        return f;
    }

     public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
      // other code
     }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
      m_webView = new WebView(getActivity());
      //other code
    return m_webview;
    }

0 个答案:

没有答案