【问题标题】:Android - Load a progress bar while BROWSER loads a page (NO WEBVIEW)Android - 在浏览器加载页面时加载进度条(无 WEBVIEW)
【发布时间】:2014-04-23 14:55:13
【问题描述】:

我正在制作一个简单的应用程序,只是为了好玩,并且在某些时候我希望它在浏览器上打开一个 URl,使用它来完成它

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);

现在,我想在浏览器加载页面时显示进度条加载,但我得到的最好的是:

ProgressBar mProgress;
mProgress = (ProgressBar) findViewById(R.id.progressBar1);
mProgress.setProgress(0);
mProgress.incrementProgressBy(1); // lots of times
mProgress.setProgress(100);

而且这只需要用户的时间,可爱,但没用。

在后台加载页面时,有什么方法可以让进度条加载?

谢谢。


更新 - 没有网页浏览

我知道 webview 会更好,但这篇文章的整个想法是了解在等待在后台打开外部应用程序时是否可以加载进度条。

【问题讨论】:

    标签: android browser progress-bar


    【解决方案1】:

    您可以通过使其可见来启动进度条,然后下载。不过,我不只是启动浏览器,而是将页面加载到 WebView 中。我将覆盖 WebView 并设置一个 onPageFinished() 侦听器,在该侦听器中我将停止 progressBar

    【讨论】:

    • 一开始我想使用 webview,但我m opening a faceapp, and as far as i saw, since october 2013 facebook kind block their apps from open on webviews.. so i droped this and im 尝试通过浏览器,不是最好的方法,但仍然不错。
    【解决方案2】:

    你的 Xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
       <TextView
           android:layout_height="wrap_content"
           android:layout_width="fill_parent"
           android:text="loading web in WebView Client"
           android:textSize="20sp"
           android:gravity="center_horizontal">      
       </TextView>
    
        <ProgressBar
           android:layout_height="wrap_content"
           android:layout_width="wrap_content"
           android:layout_gravity="center"
           android:id="@+id/progressBar1"/>     
    
       <WebView
           android:id="@+id/webview01"
           android:layout_height="wrap_content"
           android:layout_width="fill_parent"
           android:layout_weight="1">
       </WebView>
    
    
     </LinearLayout>
    

    您的活动

    public class WebViewClientDemoActivity extends Activity {
        /** Called when the activity is first created. */
    
        WebView web;
        ProgressBar progressBar;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            web = (WebView) findViewById(R.id.webview01);
            progressBar = (ProgressBar) findViewById(R.id.progressBar1);
    
            web.setWebViewClient(new myWebClient());
            web.getSettings().setJavaScriptEnabled(true);
            web.loadUrl("http://www.google.com");
        }
    
        public class myWebClient extends WebViewClient
        {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);
            }
    
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
    
                view.loadUrl(url);
                return true;
    
            }
    
            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);
    
                progressBar.setVisibility(View.GONE);
            }
        }
    
        // To handle "Back" key press event for WebView to go back to previous screen.
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event)
        {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
                web.goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
        }
    }
    

    *记得添加互联网权限

    【讨论】:

    • 感谢您的回复,但我很伤心马丁,这个想法是在 android 浏览器中打开页面,没有 webview
    猜你喜欢
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多