亲爱的
我正在使用进度条和webview的代码,进度条出现但仍然卡住,并且在我的APK中没有显示Webview。
我正在将此代码用于mainactivity.java,我只是希望在网站下载时显示进度条
代码是:
package com.example.last;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
WebView webView;
ProgressBar ProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.WebView);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
ProgressBar=(ProgressBar) findViewById(R.id.ProgressBar);
setContentView(R.layout.activity_main);
webView.loadUrl("https://google.com");
WebSettings webSettings = webView.getSettings();
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
ProgressBar.setVisibility(View.VISIBLE);
setTitle("يتم تحميل الموقع...");
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
ProgressBar.setVisibility(View.GONE);
setTitle(view.getTitle());
super.onPageFinished(view, url);
}
});
}
@Override
public void onBackPressed() {
if(webView.canGoBack()){
webView.goBack();
} else
super.onBackPressed();
}
}
谁能帮助我,告诉我该怎么办?
谢谢