我希望在需要时使此进度可见,并隐藏其页脚区域。请帮我,我不知道该怎么办。
我尝试了progressBarFooter.setVisibility(View.VISIBLE);和progressBarFooter.setVisibility(View.GONE);没用。
public class MainActivity extends AppCompatActivity {
ProgressBar superProgressBar;
WebView superWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
superProgressBar= findViewById(R.id.myProgressBar);
superWebView= findViewById(R.id.myWebView);
superProgressBar.setMax(100);
superWebView.loadUrl("http");
superWebView.getSettings().setJavaScriptEnabled(true);
superWebView.setWebViewClient(new WebViewClient());
superWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
superProgressBar.setProgress(newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
getSupportActionBar().setTitle(title);
}
});
}
@Override
public void onBackPressed(){
if (superWebView.canGoBack()){
superWebView.goBack();
}
else {
finish();
}
}
}
答案 0 :(得分:0)
这是一种控制进度条的方法。
superWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if(progress < 100 && pbar.getVisibility() == ProgressBar.GONE){
superProgressBar.setVisibility(ProgressBar.VISIBLE);
}
superProgressBar.setProgress(progress);
if(progress == 100) {
superProgressBar.setVisibility(ProgressBar.GONE);
}
}
...
});