Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android webview不加载url_Android_Webview - Fatal编程技术网

android webview不加载url

android webview不加载url,android,webview,Android,Webview,我想加载listview中列出的url,然后在列表项上单击另一个片段发送这些url,该片段基本上包含一个webview来加载该url。因此,我想将URL加载到该webview中。它打印所有日志,但不显示任何内容。我尝试的是: public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //url = getArg

我想加载listview中列出的url,然后在列表项上单击另一个片段发送这些url,该片段基本上包含一个webview来加载该url。因此,我想将URL加载到该webview中。它打印所有日志,但不显示任何内容。我尝试的是:

public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    //url = getArguments().getString("url");

    url = "http://www.google.com";

    browser = (WebView) getActivity().findViewById(R.id.webView_fullNews);

    // initialize web settings
    settings = browser.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadsImagesAutomatically(true);
    settings.setSupportMultipleWindows(true);
    settings.setAppCacheEnabled(true);
    settings.setAppCachePath( getActivity().getApplicationContext().getCacheDir().getAbsolutePath() );
    //settings.setAllowFileAccess(true);
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled(true);

    // dialog to show error
    final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();

    // loading dialog
    final ProgressDialog progress = new ProgressDialog( getActivity() );
    progress.setMessage("Loading News...");
    progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progress.setIndeterminate(true);
    progress.show();

    browser.setWebChromeClient(new WebChromeClient(){});

    browser.setWebViewClient(new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.i(TAG, "Processing webview url click...");
            view.loadUrl(url);
            return true;
        }

        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Finished loading URL: " +url);
            if (progress.isShowing()) {
                progress.dismiss();
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.e(TAG, "Error: " + description);
            Toast.makeText(getActivity(), "Ops! " + description, Toast.LENGTH_SHORT).show();
            alertDialog.setTitle("Error");
            alertDialog.setMessage(description);
            alertDialog.setButton(Button.TEXT_ALIGNMENT_CENTER, "OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    return;
                }
            });
            alertDialog.show();
        }
    });

    browser.loadUrl(String.valueOf(Uri.parse(url)));
}
xml内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:paddingTop="8dp"
          android:paddingLeft="8dp"
          android:paddingRight="8dp">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/webView_fullNews"/>

</LinearLayout>

代码应该在

     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
       View rootView = inflater.inflate(R.layout.fragment_my, container, false);
       browser = (WebView) rootView.findViewById(R.id.webView_fullNews);
            //Your webview settings
            //here
       return rootView;
    }

方法,您需要从xml中初始化和膨胀片段视图,然后设置webview设置的属性。

与论坛网站不同,我们不使用感谢、感谢的帮助或签名。看见顺便说一句,这是提前感谢,不是提前感谢。