Progressbar WebView 类似 Chrome 浏览器

Posted

技术标签:

【中文标题】Progressbar WebView 类似 Chrome 浏览器【英文标题】:Progressbar WebView like Chrome Browser 【发布时间】:2012-06-25 14:39:32 【问题描述】:

有没有人想在 Chrome 或 Reader 等 web 视图上使用进度条? 就像在底部一样:

【问题讨论】:

现在它也在 Currents 上。谷歌请求打开一个 API 或者说如何创建那个.. 【参考方案1】:

这是我用来显示进度的代码:

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity 
WebView mWvUrl;

@Override
protected void onCreate(Bundle savedInstanceState) 
    final Activity activity=this;
    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);
    activity.setProgressBarIndeterminateVisibility(false);
     mWvUrl = (WebView) findViewById(R.id.wv_url);

     mWvUrl.getSettings().setjavascriptEnabled(true);
     Button btnLoad = (Button) findViewById(R.id.btn_load);
     btnLoad.setOnClickListener(new OnClickListener() 
        @Override
        public void onClick(View v) 
             EditText etUrl = (EditText) findViewById(R.id.et_url);
              mWvUrl.loadUrl(etUrl.getText().toString());
              activity.setProgressBarIndeterminateVisibility(true);
        
    );

     mWvUrl.setWebViewClient(new WebViewClient()
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) 

                /** This prevents the loading of pages in system browser */
                return false;
            

            /** Callback method, executed when the page is completely loaded */
            @Override
            public void onPageFinished(WebView view, String url) 
                 super.onPageFinished(view, url);

                 Toast.makeText(getBaseContext(),
                                "Page loaded Completely",
                                Toast.LENGTH_SHORT).show();

                /** Hiding Indeterminate Progress Bar in the title bar*/
                activity.setProgressBarIndeterminateVisibility(false);

            

        );


@Override
public boolean onCreateOptionsMenu(Menu menu) 
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;



【讨论】:

以上是关于Progressbar WebView 类似 Chrome 浏览器的主要内容,如果未能解决你的问题,请参考以下文章

在WebView中显示ProgressDialog

进度条和 webview 问题

如何监听 WebView 完成加载 URL?

webview加载时如何隐藏progressview

Android - 将 ProgressBar 设置为垂直条而不是水平条?

如何在WebView开始加载新页面时收到通知?