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

前端 未结 6 1018
悲哀的现实
悲哀的现实 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:39

    WebView.loadUrl is run in a native thread so setProgressBarIndeterminateVisibility(false) gets called immediately pretty much. Also if you use Theme.NoTitleBar the title bar will not be shown and since the progress bar is in the title bar it won't be shown either.

    Something like this should work.

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

提交回复
热议问题