Android showing progress bar for webview in androi

2019-09-16 14:31发布

In my apps loading webpage in Web view till that webpage loads need to show progress bar after that progress bar should go..i am using an activity....reply me soon waiting for your answer

04-26 18:02:36.791: D/AndroidRuntime(25114): Shutting down VM
04-26 18:02:36.791: W/dalvikvm(25114): threadid=1: thread exiting with uncaught exception (group=0x41250438)
04-26 18:02:36.811: E/AndroidRuntime(25114): FATAL EXCEPTION: main
04-26 18:02:36.811: E/AndroidRuntime(25114): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{in.androidapplicationdotin.tneb/in.androidapplicationdotin.tneb.Onlinepayment}: java.lang.NullPointerException
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2038)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.ActivityThread.access$700(ActivityThread.java:143)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.os.Looper.loop(Looper.java:137)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.ActivityThread.main(ActivityThread.java:4960)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at java.lang.reflect.Method.invokeNative(Native Method)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at java.lang.reflect.Method.invoke(Method.java:511)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at dalvik.system.NativeStart.main(Native Method)
04-26 18:02:36.811: E/AndroidRuntime(25114): Caused by: java.lang.NullPointerException
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:143)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:65)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.AlertDialog.<init>(AlertDialog.java:98)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at in.androidapplicationdotin.tneb.Onlinepayment.<init>(Onlinepayment.java:24)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at java.lang.Class.newInstanceImpl(Native Method)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at java.lang.Class.newInstance(Class.java:1319)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
04-26 18:02:36.811: E/AndroidRuntime(25114):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2029)
04-26 18:02:36.811: E/AndroidRuntime(25114):    ... 11 more
04-26 18:02:42.111: I/GATE(25114): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
04-26 18:03:30.431: I/Ads(25114): AdLoader timed out after 60000ms while loading the HTML.
04-26 18:03:30.571: I/Ads(25114): AdLoader timed out after 60000ms while loading the HTML.
04-26 18:05:44.491: I/Process(25114): Sending signal. PID: 25114 SIG: 9

2条回答
forever°为你锁心
2楼-- · 2019-09-16 15:00

you can try this...

    private ProgressDialog dialog = new ProgressDialog(WebActivity.this);

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);
    webView = (WebView) findViewById(R.id.webView1);

    Bundle extras = getIntent().getExtras();
    String url=extras.getString("adres");

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {                  
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
        }
    });
    dialog.setMessage("Loading..Please wait.");
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
    webView.loadUrl(url);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
}
查看更多
对你真心纯属浪费
3楼-- · 2019-09-16 15:05

Try below code -

put this code in onCreate() Method

webView.setWebViewClient(new myWebClient());    
webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("Your web url");

public class myWebClient extends WebViewClient


    {
        private ProgressDialog myProgressDialog;

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
            myProgressDialog = new ProgressDialog(YourActivity.this);
            myProgressDialog.setCancelable(false);
            myProgressDialog.show();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub


            return true;

        }
        @Override
        public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);
        try{
            if (myProgressDialog != null)
                myProgressDialog.dismiss();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }


        }
        @Override
        public void doUpdateVisitedHistory(WebView view, String url,
                boolean isReload) {
            // TODO Auto-generated method stub
            super.doUpdateVisitedHistory(view, url, isReload);


        }

        @Override
        public void onLoadResource(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onLoadResource(view, url);



        }

    }

Hope this code helps you!!!!

If it is not working please let me know i will try to help you more..

查看更多
登录 后发表回答