android web视图中的动态进度条

时间:2011-02-09 16:51:29

标签: android

您好我如何在其中添加页面加载进度。当页面加载完全然后prgress栏应该向上。我想把代码放在case语句中。提前致谢 。这是代码

package com.menu;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MenuActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl("http://www.google.com");
    mWebView.setWebViewClient(new WebViewClient());
}
public boolean onCreateOptionsMenu(Menu menu) {
    new MenuInflater(getApplication())
            .inflate(R.layout.menu, menu);
    return(super.onPrepareOptionsMenu(menu));
}

public boolean onOptionsItemSelected(MenuItem item) {
     switch (item.getItemId()) {
        case R.id.Menu1:
            WebView myWebView = (WebView) findViewById(R.id.webview);
            myWebView.loadUrl("http://...........com");
                myWebView.setWebViewClient(new WebViewClient());
            break;
        case R.id.Menu2:
            WebView myWebView2 = (WebView) findViewById(R.id.webview);
            myWebView2.loadUrl("http://.................com/notice.php");
            break;
        case R.id.Menu3:
            WebView myWebView3 = (WebView) findViewById(R.id.webview);
            myWebView3.loadUrl("http://...........com/original/services.php");
                myWebView3.setWebViewClient(new WebViewClient());
            break;
        case R.id.submenu:
            Toast.makeText(this, "Sub menu", Toast.LENGTH_SHORT).show();
            break;

        default: 
            Toast.makeText(this, "Sub menu", Toast.LENGTH_SHORT).show();


            ; 
    }
    return(super.onOptionsItemSelected(item));
}
}

2 个答案:

答案 0 :(得分:5)

HI, 试试这个..在你的网页浏览中。

    mWebView.setWebChromeClient(new WebChromeClient() {

        // this will be called on page loading progress

        @Override

        public void onProgressChanged(WebView view, int newProgress) {

            super.onProgressChanged(view, newProgress);


            loadingProgressBar.setProgress(newProgress);

            // hide the progress bar if the loading is complete

            if (newProgress == 100) {

                loadingProgressBar.setVisibility(View.INVISIBLE);

            } else {

                loadingProgressBar.setVisibility(View.VISIBLE);

            }

        }

    });

参考此链接

https://sites.google.com/site/cganapathi/progressbar-in-webview-ac

答案 1 :(得分:2)

Here人们可以找到一个非常好的webview旋转轮示例