我正在尝试设置一个加载圈以显示在我的 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();
}
}