Android: The progress bar in the window's title does not display

前端 未结 6 1025
悲哀的现实
悲哀的现实 2020-12-07 15:38

I have a web view to override the built-in browser and I want to show a progress indicator on the title bar.

This is the code:

    @Override
public v         


        
6条回答
  •  庸人自扰
    2020-12-07 16:35

    In fact the correct code is (tested and working):

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        requestWindowFeature(Window.FEATURE_PROGRESS);
        currentURL = BrowserActivity.this.getIntent().getExtras().getString("currentURL");
    
        setContentView(R.layout.browser);
    
        setProgressBarIndeterminateVisibility(true);
        setProgressBarVisibility(true);
    
        try {
            mWebView = (WebView) findViewById(R.id.webview);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.setWebViewClient(new browserActivityClient());
    
            mWebView.setWebChromeClient(new WebChromeClient() {
               public void onProgressChanged(WebView view, int progress) {
                   setProgress(progress * 100);
                  if(progress == 100) {
                     setProgressBarIndeterminateVisibility(false);
                     setProgressBarVisibility(false);
                  }
               }
            });
            mWebView.loadUrl(currentURL);
        } catch (Exception e) {
            Log.e(getClass().getSimpleName(), "Browser: " + e.getMessage());
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
        } 
    }
    

提交回复
热议问题