在Android的WebView中显示的Andr​​oid进度条 [英] Android showing progress bar for webview in android

查看:216
本文介绍了在Android的WebView中显示的Andr​​oid进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序加载在Web视图的网页,直到该网页加载需要显示进度条后,进度条go..i应该正在使用的活动....回复我很快就等着你的答案

  18 04-26:02:36.791:D / AndroidRuntime(25114):关闭VM
04-26 18:02:36.791:W / dalvikvm(25114):主题ID = 1:螺纹未捕获的异常(组= 0x41250438)退出
04-26 18:02:36.811:E / AndroidRuntime(25114):致命异常:主要
04-26 18:02:36.811:E / AndroidRuntime(25114):了java.lang.RuntimeException:无法实例活动ComponentInfo {in.androidapplicationdotin.tneb / in.androidapplicationdotin.tneb.Onlinepayment}:显示java.lang.NullPointerException
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2038)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.ActivityThread.access $ 700(ActivityThread.java:143)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1241)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.os.Handler.dispatchMessage(Handler.java:99)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.os.Looper.loop(Looper.java:137)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.ActivityThread.main(ActivityThread.java:4960)
04-26 18:02:36.811:E / AndroidRuntime(25114):在java.lang.reflect.Method.invokeNative(本机方法)
04-26 18:02:36.811:E / AndroidRuntime(25114):在java.lang.reflect.Method.invoke(Method.java:511)
04-26 18:02:36.811:E / AndroidRuntime(25114):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1038)
04-26 18:02:36.811:E / AndroidRuntime(25114):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
04-26 18:02:36.811:E / AndroidRuntime(25114):在dalvik.system.NativeStart.main(本机方法)
04-26 18:02:36.811:E / AndroidRuntime(25114):致:显示java.lang.NullPointerException
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:143)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:65)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
。04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.AlertDialog<&初始化GT;(AlertDialog.java:98)
。04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.ProgressDialog<&初始化GT;(ProgressDialog.java:77)
。04-26 18:02:36.811:E / AndroidRuntime(25114):在in.androidapplicationdotin.tneb.Onlinepayment<&初始化GT;(Onlinepayment.java:24)
04-26 18:02:36.811:E / AndroidRuntime(25114):在java.lang.Class.newInstanceImpl(本机方法)
04-26 18:02:36.811:E / AndroidRuntime(25114):在java.lang.Class.newInstance(Class.java:1319)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.Instrumentation.newActivity(Instrumentation.java:1068)
04-26 18:02:36.811:E / AndroidRuntime(25114):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2029)
04-26 18:02:36.811:E / AndroidRuntime(25114):... 11个
04-26 18:02:42.111:I / GATE(25114):其中,GATE-M> DEV_ACTION_COMPLETED< / GATE-M>
04-26 18:03:30.431:I /广告(25114):AdLoader 60000毫秒后超时,同时加载HTML。
04-26 18:03:30.571:I /广告(25114):AdLoader 60000毫秒后超时,同时加载HTML。
04-26 18:05:44.491:I /流程(25114):发送信号。 PID:25114 SIG:9


解决方案

尝试下面code -

把这个code在的onCreate()方法

  webView.setWebViewClient(新myWebClient());
webView.getSettings()setJavaScriptEnabled(真)。
        webView.loadUrl(您的Web URL);公共类myWebClient扩展WebViewClient
    {
        私人ProgressDialog myProgressDialog;        @覆盖
        公共无效onPageStarted(的WebView视图,字符串URL,位图图标){
            // TODO自动生成方法存根
            super.onPageStarted(查看,网址,图标);
            myProgressDialog =新ProgressDialog(YourActivity.this);
            myProgressDialog.setCancelable(假);
            myProgressDialog.show();
        }        @覆盖
        公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){
            // TODO自动生成方法存根
            返回true;        }
        @覆盖
        公共无效onPageFinished(的WebView视图,字符串URL){
        // TODO自动生成方法存根
        super.onPageFinished(查看,网址);
        尝试{
            如果(myProgressDialog!= NULL)
                myProgressDialog.dismiss();
        }
        赶上(例外五)
        {
            e.printStackTrace();
        }
        }
        @覆盖
        公共无效doUpdateVisitedHistory(的WebView视图,字符串URL,
                布尔isReload){
            // TODO自动生成方法存根
            super.doUpdateVisitedHistory(查看,网址,isReload);
        }        @覆盖
        公共无效onLoadResource(的WebView视图,字符串URL){
            // TODO自动生成方法存根
            super.onLoadResource(查看,网址);        }    }

希望这code可以帮助你!!!!

如果它不能正常工作,请让我知道,我会尽力帮助你更..

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

解决方案

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..

这篇关于在Android的WebView中显示的Andr​​oid进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆