WebChromeClient无法运行Android

WebChromeClient无法运行Android,android,webview,Android,Webview,我有一个进度条,一个全屏视频播放方法(用于全屏播放youtube视频),以及公共布尔值应该覆盖来处理WebView中的URL,但我无法让这三个方法一起工作,我尝试了以下三种方法,似乎我需要重复的webviewClient和WebChromeClient,以使依赖它们的一切工作正常 方法1-进度条不工作(卡在0%上) 方法2-全屏不工作 public class MainActivity extends Activity { private WebView mWebVie

我有一个进度条,一个全屏视频播放方法(用于全屏播放youtube视频),以及公共布尔值应该覆盖来处理WebView中的URL,但我无法让这三个方法一起工作,我尝试了以下三种方法,似乎我需要重复的webviewClient和WebChromeClient,以使依赖它们的一切工作正常

方法1-进度条不工作(卡在0%上)

方法2-全屏不工作

    public class MainActivity extends Activity {

        private WebView mWebView;
        private EditText urlEditText;
        private ProgressBar progress;
        // FULL-SCREEN VIDEO-1
        private LinearLayout mContentView;
        private FrameLayout mCustomViewContainer;
        private View mCustomView;
        private WebChromeClient.CustomViewCallback mCustomViewCallback;
        FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
        private WebChromeClient mWebChromeClient;

        // FULL-SCREEN VIDEO-1

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            // FULL-SCREEN VIDEO-2
            mContentView = (LinearLayout) findViewById(R.id.linearlayout);
            mWebView = (WebView) findViewById(R.id.webView);
            mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);

            mWebChromeClient = new WebChromeClient() {

                @Override
                public void onShowCustomView(View view,
                        WebChromeClient.CustomViewCallback callback) {
                    // if a view already exists then immediately terminate the new
                    // one
                    if (mCustomView != null) {
                        callback.onCustomViewHidden();
                        return;
                    }

                    // Add the custom view to its container.
                    mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
                    mCustomView = view;
                    mCustomViewCallback = callback;

                    // hide main browser view
                    mContentView.setVisibility(View.GONE);

                    // Finally show the custom view container.
                    mCustomViewContainer.setVisibility(View.VISIBLE);
                    mCustomViewContainer.bringToFront();
                }

                @Override
                public void onHideCustomView() {
                    if (mCustomView == null)
                        return;

                    // Hide the custom view.
                    mCustomView.setVisibility(View.GONE);
                    // Remove the custom view from its container.
                    mCustomViewContainer.removeView(mCustomView);
                    mCustomView = null;
                    mCustomViewContainer.setVisibility(View.GONE);
                    mCustomViewCallback.onCustomViewHidden();

                    // Show the content view.
                    mContentView.setVisibility(View.VISIBLE);
                }
            };
            // FULL-SCREEN VIDEO-2
            WebSettings webSettings = mWebView.getSettings();
            webSettings.setPluginState(WebSettings.PluginState.ON);
            webSettings.setJavaScriptEnabled(true);
            webSettings.setUseWideViewPort(true);
            webSettings.setLoadWithOverviewMode(true);

            mWebView.loadUrl("http://www.google.com");
            mWebView.setWebViewClient(new HelloWebViewClient());
            mWebView.setWebChromeClient(new mWebChromeClient());
            // Download manager
            mWebView.setDownloadListener(new DownloadListener() {
                public void onDownloadStart(String url, String userAgent,
                        String contentDisposition, String mimetype,
                        long contentLength) {
                    Request request = new Request(Uri.parse(url));
                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    request.setDestinationInExternalPublicDir(
                            Environment.DIRECTORY_DOWNLOADS, "download");
                    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                    dm.enqueue(request);

                }
            });
            // **//

            // URL BAR AND PROGRESS BAR

            progress = (ProgressBar) findViewById(R.id.progressBar);
            progress.setMax(100);

            urlEditText = (EditText) findViewById(R.id.urlField);
            // Use Done/search button in keyboard as go button
            urlEditText.setOnEditorActionListener(new OnEditorActionListener() {
                public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
                    // Toast.makeText(getApplicationContext(), "some key pressed",
                    // Toast.LENGTH_LONG).show();
                    String url = urlEditText.getText().toString();
                    if (url.endsWith(".ac") || url.endsWith(".ac.uk")
                            || url.endsWith(".ad") || url.endsWith(".zw")) {
                        if (!url.startsWith("http://")
                                && !url.startsWith("https://")) {
                            url = "http://" + url;

                        }
                    } else
                        url = "https://www.google.com/search?q="
                                + url.replace(" ", "+");// Prefix (replace spaces
                                                        // with a '+' sign)
                    mWebView.loadUrl(url);

                    if (validateUrl(url)) {
                        mWebView.getSettings().setJavaScriptEnabled(true);
                        mWebView.loadUrl(url);

                        MainActivity.this.progress.setProgress(10);
                    }
                    return false;
                }

                private boolean validateUrl(String url) {
                    return true;

                }
            });
            // **//
        }

        private class mWebChromeClient extends WebChromeClient {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {

                MainActivity.this.setValue(newProgress);
                super.onProgressChanged(view, newProgress);
            }
        }

        public void setValue(int progress) {
            this.progress.setProgress(progress);
        }

        private class HelloWebViewClient extends WebViewClient {

            @Override
            public boolean shouldOverrideUrlLoading(WebView webview, String url) {

                webview.loadUrl(url);

                return true;
            }
        }

        // FULL-SCREEN VIDEO-3
        @Override
        protected void onStop() {// plays video outside frame on back button and
                                    // prevents from going back

            super.onStop();
            if (mCustomView != null) {
                if (mCustomViewCallback != null)
                    mCustomViewCallback.onCustomViewHidden();
                mCustomView = null;
            }

        }

        @Override
        public void onBackPressed() {// hide custom view (in which the video plays)
                                        // on back button

            super.onBackPressed();
            if (mCustomView != null) {
                mWebChromeClient.onHideCustomView();
            } else {
                finish();
            }
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {// prevents the
                                                                // custom view from
                                                                // running in
                                                                // background when
                                                                // app is closed
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
            // FULL-SCREEN VIDEO-3
        }
    }
    public class MainActivity extends Activity {

        private WebView mWebView;
        private EditText urlEditText;
        private ProgressBar progress;
        // FULL-SCREEN VIDEO-1
        private LinearLayout mContentView;
        private FrameLayout mCustomViewContainer;
        private View mCustomView;
        private WebChromeClient.CustomViewCallback mCustomViewCallback;
        FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
        private WebChromeClient mWebChromeClient;

        // FULL-SCREEN VIDEO-1

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            // FULL-SCREEN VIDEO-2
            mContentView = (LinearLayout) findViewById(R.id.linearlayout);
            mWebView = (WebView) findViewById(R.id.webView);
            mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);

            mWebChromeClient = new WebChromeClient() {

                @Override
                public void onShowCustomView(View view,
                        WebChromeClient.CustomViewCallback callback) {
                    // if a view already exists then immediately terminate the new
                    // one
                    if (mCustomView != null) {
                        callback.onCustomViewHidden();
                        return;
                    }

                    // Add the custom view to its container.
                    mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
                    mCustomView = view;
                    mCustomViewCallback = callback;

                    // hide main browser view
                    mContentView.setVisibility(View.GONE);

                    // Finally show the custom view container.
                    mCustomViewContainer.setVisibility(View.VISIBLE);
                    mCustomViewContainer.bringToFront();
                }

                @Override
                public void onHideCustomView() {
                    if (mCustomView == null)
                        return;

                    // Hide the custom view.
                    mCustomView.setVisibility(View.GONE);
                    // Remove the custom view from its container.
                    mCustomViewContainer.removeView(mCustomView);
                    mCustomView = null;
                    mCustomViewContainer.setVisibility(View.GONE);
                    mCustomViewCallback.onCustomViewHidden();

                    // Show the content view.
                    mContentView.setVisibility(View.VISIBLE);
                }
            };
            // FULL-SCREEN VIDEO-2
            WebSettings webSettings = mWebView.getSettings();
            webSettings.setPluginState(WebSettings.PluginState.ON);
            webSettings.setJavaScriptEnabled(true);
            webSettings.setUseWideViewPort(true);
            webSettings.setLoadWithOverviewMode(true);

            mWebView.loadUrl("http://www.google.com");
            mWebView.setWebChromeClient(new HelloWebViewClient());

            // Download manager
            mWebView.setDownloadListener(new DownloadListener() {
                public void onDownloadStart(String url, String userAgent,
                        String contentDisposition, String mimetype,
                        long contentLength) {
                    Request request = new Request(Uri.parse(url));
                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    request.setDestinationInExternalPublicDir(
                            Environment.DIRECTORY_DOWNLOADS, "download");
                    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                    dm.enqueue(request);

                }
            });
            // **//

            // URL BAR AND PROGRESS BAR

            progress = (ProgressBar) findViewById(R.id.progressBar);
            progress.setMax(100);

            urlEditText = (EditText) findViewById(R.id.urlField);
            // Use Done/search button in keyboard as go button
            urlEditText.setOnEditorActionListener(new OnEditorActionListener() {
                public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
                    // Toast.makeText(getApplicationContext(), "some key pressed",
                    // Toast.LENGTH_LONG).show();
                    String url = urlEditText.getText().toString();
                    if (url.endsWith(".ac") || url.endsWith(".ac.uk")
                            || url.endsWith(".ad") || url.endsWith(".zw")) {
                        if (!url.startsWith("http://")
                                && !url.startsWith("https://")) {
                            url = "http://" + url;

                        }
                    } else
                        url = "https://www.google.com/search?q="
                                + url.replace(" ", "+");// Prefix (replace spaces
                                                        // with a '+' sign)
                    mWebView.loadUrl(url);

                    if (validateUrl(url)) {
                        mWebView.getSettings().setJavaScriptEnabled(true);
                        mWebView.loadUrl(url);

                        MainActivity.this.progress.setProgress(10);
                    }
                    return false;
                }

                private boolean validateUrl(String url) {
                    return true;

                }
            });
            // **//
        }

        private class HelloWebViewClient extends WebChromeClient {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                MainActivity.this.setValue(newProgress);
                super.onProgressChanged(view, newProgress);
            }
        }

        public void setValue(int progress) {
            this.progress.setProgress(progress);
        }

        private class HelloWebViewClient1 extends WebViewClient {

            @Override
            public boolean shouldOverrideUrlLoading(WebView webview, String url) {
                webview.setWebChromeClient(mWebChromeClient);
                webview.loadUrl(url);

                return true;
            }
        }

        // FULL-SCREEN VIDEO-3
        @Override
        protected void onStop() {// plays video outside frame on back button and
                                    // prevents from going back

            super.onStop();
            if (mCustomView != null) {
                if (mCustomViewCallback != null)
                    mCustomViewCallback.onCustomViewHidden();
                mCustomView = null;
            }

        }

        @Override
        public void onBackPressed() {// hide custom view (in which the video plays)
                                        // on back button

            super.onBackPressed();
            if (mCustomView != null) {
                mWebChromeClient.onHideCustomView();
            } else {
                finish();
            }
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {// prevents the
                                                                // custom view from
                                                                // running in
                                                                // background when
                                                                // app is closed
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
            // FULL-SCREEN VIDEO-3
        }
    }
方法3-应覆盖以下加载不起作用

    public class MainActivity extends Activity {

        private WebView mWebView;
        private EditText urlEditText;
        private ProgressBar progress;
        // FULL-SCREEN VIDEO-1
        private LinearLayout mContentView;
        private FrameLayout mCustomViewContainer;
        private View mCustomView;
        private WebChromeClient.CustomViewCallback mCustomViewCallback;
        FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
        private WebChromeClient mWebChromeClient;

        // FULL-SCREEN VIDEO-1

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            // FULL-SCREEN VIDEO-2
            mContentView = (LinearLayout) findViewById(R.id.linearlayout);
            mWebView = (WebView) findViewById(R.id.webView);
            mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);

            mWebChromeClient = new WebChromeClient() {

                @Override
                public void onShowCustomView(View view,
                        WebChromeClient.CustomViewCallback callback) {
                    // if a view already exists then immediately terminate the new
                    // one
                    if (mCustomView != null) {
                        callback.onCustomViewHidden();
                        return;
                    }

                    // Add the custom view to its container.
                    mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
                    mCustomView = view;
                    mCustomViewCallback = callback;

                    // hide main browser view
                    mContentView.setVisibility(View.GONE);

                    // Finally show the custom view container.
                    mCustomViewContainer.setVisibility(View.VISIBLE);
                    mCustomViewContainer.bringToFront();
                }

                @Override
                public void onHideCustomView() {
                    if (mCustomView == null)
                        return;

                    // Hide the custom view.
                    mCustomView.setVisibility(View.GONE);
                    // Remove the custom view from its container.
                    mCustomViewContainer.removeView(mCustomView);
                    mCustomView = null;
                    mCustomViewContainer.setVisibility(View.GONE);
                    mCustomViewCallback.onCustomViewHidden();

                    // Show the content view.
                    mContentView.setVisibility(View.VISIBLE);
                }
            };
            // FULL-SCREEN VIDEO-2
            WebSettings webSettings = mWebView.getSettings();
            webSettings.setPluginState(WebSettings.PluginState.ON);
            webSettings.setJavaScriptEnabled(true);
            webSettings.setUseWideViewPort(true);
            webSettings.setLoadWithOverviewMode(true);

            mWebView.loadUrl("http://www.google.com");
            mWebView.setWebViewClient(new HelloWebViewClient());
            mWebView.setWebChromeClient(new mWebChromeClient());
            // Download manager
            mWebView.setDownloadListener(new DownloadListener() {
                public void onDownloadStart(String url, String userAgent,
                        String contentDisposition, String mimetype,
                        long contentLength) {
                    Request request = new Request(Uri.parse(url));
                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    request.setDestinationInExternalPublicDir(
                            Environment.DIRECTORY_DOWNLOADS, "download");
                    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                    dm.enqueue(request);

                }
            });
            // **//

            // URL BAR AND PROGRESS BAR

            progress = (ProgressBar) findViewById(R.id.progressBar);
            progress.setMax(100);

            urlEditText = (EditText) findViewById(R.id.urlField);
            // Use Done/search button in keyboard as go button
            urlEditText.setOnEditorActionListener(new OnEditorActionListener() {
                public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
                    // Toast.makeText(getApplicationContext(), "some key pressed",
                    // Toast.LENGTH_LONG).show();
                    String url = urlEditText.getText().toString();
                    if (url.endsWith(".ac") || url.endsWith(".ac.uk")
                            || url.endsWith(".ad") || url.endsWith(".zw")) {
                        if (!url.startsWith("http://")
                                && !url.startsWith("https://")) {
                            url = "http://" + url;

                        }
                    } else
                        url = "https://www.google.com/search?q="
                                + url.replace(" ", "+");// Prefix (replace spaces
                                                        // with a '+' sign)
                    mWebView.loadUrl(url);

                    if (validateUrl(url)) {
                        mWebView.getSettings().setJavaScriptEnabled(true);
                        mWebView.loadUrl(url);

                        MainActivity.this.progress.setProgress(10);
                    }
                    return false;
                }

                private boolean validateUrl(String url) {
                    return true;

                }
            });
            // **//
        }

        private class mWebChromeClient extends WebChromeClient {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {

                MainActivity.this.setValue(newProgress);
                super.onProgressChanged(view, newProgress);
            }
        }

        public void setValue(int progress) {
            this.progress.setProgress(progress);
        }

        private class HelloWebViewClient extends WebViewClient {

            @Override
            public boolean shouldOverrideUrlLoading(WebView webview, String url) {

                webview.loadUrl(url);

                return true;
            }
        }

        // FULL-SCREEN VIDEO-3
        @Override
        protected void onStop() {// plays video outside frame on back button and
                                    // prevents from going back

            super.onStop();
            if (mCustomView != null) {
                if (mCustomViewCallback != null)
                    mCustomViewCallback.onCustomViewHidden();
                mCustomView = null;
            }

        }

        @Override
        public void onBackPressed() {// hide custom view (in which the video plays)
                                        // on back button

            super.onBackPressed();
            if (mCustomView != null) {
                mWebChromeClient.onHideCustomView();
            } else {
                finish();
            }
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {// prevents the
                                                                // custom view from
                                                                // running in
                                                                // background when
                                                                // app is closed
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
            // FULL-SCREEN VIDEO-3
        }
    }
    public class MainActivity extends Activity {

        private WebView mWebView;
        private EditText urlEditText;
        private ProgressBar progress;
        // FULL-SCREEN VIDEO-1
        private LinearLayout mContentView;
        private FrameLayout mCustomViewContainer;
        private View mCustomView;
        private WebChromeClient.CustomViewCallback mCustomViewCallback;
        FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
        private WebChromeClient mWebChromeClient;

        // FULL-SCREEN VIDEO-1

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            // FULL-SCREEN VIDEO-2
            mContentView = (LinearLayout) findViewById(R.id.linearlayout);
            mWebView = (WebView) findViewById(R.id.webView);
            mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);

            mWebChromeClient = new WebChromeClient() {

                @Override
                public void onShowCustomView(View view,
                        WebChromeClient.CustomViewCallback callback) {
                    // if a view already exists then immediately terminate the new
                    // one
                    if (mCustomView != null) {
                        callback.onCustomViewHidden();
                        return;
                    }

                    // Add the custom view to its container.
                    mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
                    mCustomView = view;
                    mCustomViewCallback = callback;

                    // hide main browser view
                    mContentView.setVisibility(View.GONE);

                    // Finally show the custom view container.
                    mCustomViewContainer.setVisibility(View.VISIBLE);
                    mCustomViewContainer.bringToFront();
                }

                @Override
                public void onHideCustomView() {
                    if (mCustomView == null)
                        return;

                    // Hide the custom view.
                    mCustomView.setVisibility(View.GONE);
                    // Remove the custom view from its container.
                    mCustomViewContainer.removeView(mCustomView);
                    mCustomView = null;
                    mCustomViewContainer.setVisibility(View.GONE);
                    mCustomViewCallback.onCustomViewHidden();

                    // Show the content view.
                    mContentView.setVisibility(View.VISIBLE);
                }
            };
            // FULL-SCREEN VIDEO-2
            WebSettings webSettings = mWebView.getSettings();
            webSettings.setPluginState(WebSettings.PluginState.ON);
            webSettings.setJavaScriptEnabled(true);
            webSettings.setUseWideViewPort(true);
            webSettings.setLoadWithOverviewMode(true);

            mWebView.loadUrl("http://www.google.com");
            mWebView.setWebChromeClient(new HelloWebViewClient());

            // Download manager
            mWebView.setDownloadListener(new DownloadListener() {
                public void onDownloadStart(String url, String userAgent,
                        String contentDisposition, String mimetype,
                        long contentLength) {
                    Request request = new Request(Uri.parse(url));
                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    request.setDestinationInExternalPublicDir(
                            Environment.DIRECTORY_DOWNLOADS, "download");
                    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                    dm.enqueue(request);

                }
            });
            // **//

            // URL BAR AND PROGRESS BAR

            progress = (ProgressBar) findViewById(R.id.progressBar);
            progress.setMax(100);

            urlEditText = (EditText) findViewById(R.id.urlField);
            // Use Done/search button in keyboard as go button
            urlEditText.setOnEditorActionListener(new OnEditorActionListener() {
                public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
                    // Toast.makeText(getApplicationContext(), "some key pressed",
                    // Toast.LENGTH_LONG).show();
                    String url = urlEditText.getText().toString();
                    if (url.endsWith(".ac") || url.endsWith(".ac.uk")
                            || url.endsWith(".ad") || url.endsWith(".zw")) {
                        if (!url.startsWith("http://")
                                && !url.startsWith("https://")) {
                            url = "http://" + url;

                        }
                    } else
                        url = "https://www.google.com/search?q="
                                + url.replace(" ", "+");// Prefix (replace spaces
                                                        // with a '+' sign)
                    mWebView.loadUrl(url);

                    if (validateUrl(url)) {
                        mWebView.getSettings().setJavaScriptEnabled(true);
                        mWebView.loadUrl(url);

                        MainActivity.this.progress.setProgress(10);
                    }
                    return false;
                }

                private boolean validateUrl(String url) {
                    return true;

                }
            });
            // **//
        }

        private class HelloWebViewClient extends WebChromeClient {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                MainActivity.this.setValue(newProgress);
                super.onProgressChanged(view, newProgress);
            }
        }

        public void setValue(int progress) {
            this.progress.setProgress(progress);
        }

        private class HelloWebViewClient1 extends WebViewClient {

            @Override
            public boolean shouldOverrideUrlLoading(WebView webview, String url) {
                webview.setWebChromeClient(mWebChromeClient);
                webview.loadUrl(url);

                return true;
            }
        }

        // FULL-SCREEN VIDEO-3
        @Override
        protected void onStop() {// plays video outside frame on back button and
                                    // prevents from going back

            super.onStop();
            if (mCustomView != null) {
                if (mCustomViewCallback != null)
                    mCustomViewCallback.onCustomViewHidden();
                mCustomView = null;
            }

        }

        @Override
        public void onBackPressed() {// hide custom view (in which the video plays)
                                        // on back button

            super.onBackPressed();
            if (mCustomView != null) {
                mWebChromeClient.onHideCustomView();
            } else {
                finish();
            }
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {// prevents the
                                                                // custom view from
                                                                // running in
                                                                // background when
                                                                // app is closed
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
            // FULL-SCREEN VIDEO-3
        }
    }

你的设备上安装了哪个Android操作系统版本?“不工作”具体是什么?如果您能提供更多关于您遇到的确切问题的详细信息,那就太好了。至少在方法3中,WebViewClient从未连接到webView。那么您的shouldOverrideUrlLoading实现应该如何让webView知道呢?这可以用switch语句纠正吗?您想实现什么?你看到了什么结果?仅仅在这里复制和粘贴代码并不能得到有用的答案。