简体   繁体   English

在 WebView 上的选项卡主机中添加进度条

[英]Add Progress Bar in Tab Host on WebView

Hello Well i'm very basic in java, here is my java code about my activity class, i can't add progress bar in webview, please help me in my code Here My Java Code: Hello Well i'm very basic in java, here is my java code about my activity class, i can't add progress bar in webview, please help me in my code Here My Java Code:

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;
//Set Activity Irancell:
public class Irancell extends Activity {
WebView Irancell_Charge;
//Start App Code at here:
@Override
// Set iCicle:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
//Load Irancel Buy Creadit Page:
Irancell_Charge=new WebView(this);
setContentView(Irancell_Charge);
Irancell_Charge.getSettings().setJavaScriptEnabled(true);
Irancell_Charge.loadUrl("http://www.echarge.ir/Templates/irancellshop/m/");
//Text Label:
Toast
.makeText(this, "MTN Irancell Recharge Cards...", Toast.LENGTH_LONG)
.show();
}
}

Thanks...谢谢...

This will show a spinner when the page is navigating.这将在页面导航时显示一个微调器。 Every time the user navigates to a new page, a loader / progress will appear.每次用户导航到新页面时,都会出现一个加载器/进度。

I use a WebViewClient to achieve this.我使用 WebViewClient 来实现这一点。

package sherif.android.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebClientTestActivity extends Activity {
    private ProgressDialog mSpinner;
    private WebView webView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //initialise your spinner
        mSpinner = new ProgressDialog(this);
        mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mSpinner.setMessage("Loading..."); 
        //initialise your webview
        webView = new WebView(this);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://sherifandroid.blogspot.com/");
        webView.setWebViewClient(new SherifWebClient());
        setContentView(webView);
    }
    private class SherifWebClient extends WebViewClient {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            mSpinner.show();
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mSpinner.dismiss();
        }

    }
}

To show the progression with an animated progress bar you have to implement these codes:要使用动画进度条显示进度,您必须实现以下代码:

ProgressDialog progressDialog;
progressDialog = new ProgressDialog(mContext);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM