0

我正在尝试设置一个加载圈以显示在我的 android web 视图应用程序中。自从我开始以来,我已经取得了很大的进步。现在我收到 setProgress 行的错误。

错误信息是:

未为类型 new WebChromeClient(){} 定义方法 setProgress(int)

import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.webkit.WebChromeClient;

public class MainActivity extends Activity 
{   
    //Configure the webview setup in the xml layout
    public WebView myWebView;


     @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            //Remove title bar as we already have it in the web app
            this.requestWindowFeature(Window.FEATURE_NO_TITLE);

            getWindow().requestFeature(Window.FEATURE_PROGRESS);
            //Point to the content view defined in XML
            setContentView(R.layout.activity_main);
            myWebView = (WebView) findViewById(R.id.webview);
            myWebView.getSettings().setJavaScriptEnabled(true);
            myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);


            WebSettings webSettings = myWebView.getSettings();
            //Yes, we want javascript, pls.

            webSettings.setJavaScriptEnabled(true);
            //Make sure links in the webview is handled by the webview and not sent to a full browser
            myWebView.setWebViewClient(new WebViewClient());
            //And let the fun begin
            myWebView.loadUrl("http://www.google.com");

            myWebView.setWebChromeClient(new WebChromeClient() {
                 public void onProgressChanged(WebView view, int progress) {
                  // Activities and WebViews measure progress with different scales.
                  // The progress meter will automatically disappear when we reach 100%
                  this.setProgress(progress * 100);

                 }});

        }



    @Override
    public void onBackPressed(){
        myWebView.goBack();
    }


}
4

1 回答 1

3

改为

MainActivity.this.setProgress(progress * 100);

要不就

setProgress(progress * 100);

这样您就可以明确引用父类实例。仅thisWebChromeClient引用该类的实例时执行操作,因此会出现编译时错误。

由于您正在使用 WebView,请参阅文档以获取有关WebViews 和其他所有相关内容(包括客户端)的更多信息。

于 2013-02-07T00:30:19.190 回答