本文介绍了电话能见度OnPageFinished - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调用知名度的页面加载停止的时候?我想使进度不可见的,code我使用的是不是让我重写它

code

公共无效onPageFinished(的WebView视图,字符串URL){

  findViewById(R.id.progressBar1).setVisibility(View.GONE);
}

活动

 进口android.app.Activity;
进口android.graphics.Bitmap;
进口android.os.Bundle;
进口android.view.KeyEvent;
进口android.view.Menu;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.webkit.CookieManager;
进口android.webkit.WebChromeClient;
进口android.webkit.WebSettings;
进口android.webkit.WebSettings.PluginState;
进口android.webkit.WebView;
进口android.webkit.WebViewClient;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.ProgressBar;公共类浏览器扩展活动{
    私人的WebView web视图;
    私人的EditText urlEditText;
    私人进度进展情况;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_browser);
        web视图=(的WebView)findViewById(R.id.webView1);
        webView.setWebChromeClient(新MyWebViewClient());        。CookieManager.getInstance()setAcceptCookie(真); //打开Cookies
        webView.getSettings()setJavaScriptEnabled(真); //启用Java脚本
        webView.setWebViewClient(新HelloWebViewClient());
        webView.loadUrl(https://www.facebook.com/); //设为首页
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); //删除滚动条
        webView.getSettings()setDefaultFontSize(12); //设置字体大小
        。webView.getSettings()setLoadsImagesAutomatically(真); //启用图像加载
        。webView.getSettings()setPluginState(PluginState.ON); //启用Flash
        webView.setBackgroundColor(00000000); //透明屏幕加载时
        //webView.getSettings().setBuiltInZoomControls(true);//Set缩放控制        webView.getSettings()setAppCacheMaxSize(1024 * 1024 * 8); //设置高速缓存(8MB)
        字符串appCachePath = getApplicationContext()getCacheDir()getAbsolutePath(); //设置缓存(8MB)
        webView.getSettings()setAppCachePath(appCachePath); //设置缓存(8MB)
        。webView.getSettings()setAllowFileAccess(TRUE); //设置缓存(8MB)
        webView.getSettings()setAppCacheEnabled(TRUE); //设置缓存(8MB)
        webView.getSettings()setCacheMode(WebSettings.LOAD_DEFAULT); //设置缓存(8MB)
        ////// 888888888888888888888888888888888888888888888888888888888888888888888        进度=(进度)findViewById(R.id.progressBar1);
        progress.setMax(100);        按钮的OpenURL =(按钮)findViewById(R.id.goButton);
        openUrl.setOnClickListener(新OnClickListener(){            @覆盖
            公共无效的onClick(查看视图){
                。字符串URL = urlEditText.getText()的toString();
                如果(validateUrl(URL)){
                    webView.getSettings()setJavaScriptEnabled(真)。
                    webView.loadUrl(URL);                    Browser.this.progress.setProgress(10);
        }
    }    私人布尔va​​lidateUrl(字符串URL){
        返回true;
    }
            });    }    私有类MyWebViewClient扩展WebChromeClient {
        @覆盖
        公共无效onProgressChanged(的WebView观点,诠释newProgress){
            Browser.this.setValue(newProgress);
            super.onProgressChanged(查看,newProgress);
        }
    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }    公共无效的setValue(INT进展){
        this.progress.setProgress(进度);
    }
    ///// 88888888888888888888888888888888888888888888888888888888888888888888888
    私有类HelloWebViewClient扩展WebViewClient {
        @覆盖
        公共布尔shouldOverrideUrlLoading(的WebView的WebView,字符串URL)
        {
            webview.loadUrl(URL);
            返回true;
        }
    }
@覆盖
 公共布尔的onkeydown(INT键code,KeyEvent的事件)
 {     如果((键code == KeyEvent.KEY code_BACK)及和放大器; webView.canGoBack())    {
webView.goBack();
    返回true;
    }
    返回super.onKeyDown(键code,事件);
}
}


解决方案

您应该能够只是折腾它的权利在那里。

 私有类HelloWebViewClient扩展WebViewClient {    @覆盖
    公共无效onPageFinished(的WebView视图,最终字符串URL){
        progress.setVisibility(View.GONE); //或View.INVISIBLE,无论适合您的需要
        //或者这更加清晰:Browser.this.progress.setVisibility(View.GONE);
    }    @覆盖
    公共布尔shouldOverrideUrlLoading(的WebView的WebView,字符串URL){        webview.loadUrl(URL);
        返回true;
    }
}

how to call visibility when the page stops loading? i want to make the progressbar invisible but the code i am using is not letting me override it

code

public void onPageFinished(WebView view, String url) {

    findViewById(R.id.progressBar1).setVisibility(View.GONE);
}

Activity

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;

public class Browser extends Activity {
    private WebView webView;
    private EditText urlEditText;
    private ProgressBar progress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browser);


        webView = (WebView) findViewById(R.id.webView1);
        webView.setWebChromeClient(new MyWebViewClient()); 

        CookieManager.getInstance().setAcceptCookie(true);//Enable Cookies
        webView.getSettings().setJavaScriptEnabled(true);//Enable Java Script
        webView.setWebViewClient(new HelloWebViewClient());
        webView.loadUrl("https://www.facebook.com/"); //Set Home page
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);//Remove ScrollBars
        webView.getSettings().setDefaultFontSize(12);//Set Font Size
        webView.getSettings().setLoadsImagesAutomatically(true);//Enable Image Loading
        webView.getSettings().setPluginState(PluginState.ON);//Enable Flash
        webView.setBackgroundColor(0x00000000);//Transparent Screen When Loading
        //webView.getSettings().setBuiltInZoomControls(true);//Set Zoom Controls 

        webView.getSettings().setAppCacheMaxSize(1024*1024*8);//Set Cache (8mb)
        String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();//Set Cache (8mb)
        webView.getSettings().setAppCachePath(appCachePath);//Set Cache (8mb)
        webView.getSettings().setAllowFileAccess(true);//Set Cache (8mb)
        webView.getSettings().setAppCacheEnabled(true);//Set Cache (8mb)
        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);//Set Cache (8mb)


        //////888888888888888888888888888888888888888888888888888888888888888888888   

        progress = (ProgressBar) findViewById(R.id.progressBar1);
        progress.setMax(100);

        Button openUrl = (Button) findViewById(R.id.goButton);
        openUrl.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                String url = urlEditText.getText().toString();
                if (validateUrl(url)) {
                    webView.getSettings().setJavaScriptEnabled(true);
                    webView.loadUrl(url);

                    Browser.this.progress.setProgress(10);
        }
    }

    private boolean validateUrl(String url) {
        return true;
    }
            });

    }

    private class MyWebViewClient extends WebChromeClient {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {         
            Browser.this.setValue(newProgress);
            super.onProgressChanged(view, newProgress);
        }
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void setValue(int progress) {
        this.progress.setProgress(progress);       
    }
    /////88888888888888888888888888888888888888888888888888888888888888888888888


    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView webview, String url)
        {


            webview.loadUrl(url);
            return true;
        }
    }
@Override
 public boolean onKeyDown(int keyCode, KeyEvent event)
 {

     if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack())

    {
webView.goBack();
    return true;
    }
    return super.onKeyDown(keyCode, event);
}
}
解决方案

You should be able to just toss it right in there.

private class HelloWebViewClient extends WebViewClient {

    @Override
    public void onPageFinished(WebView view, final String url) {
        progress.setVisibility(View.GONE); // or View.INVISIBLE, whatever suits your needs
        // Or this for more clarity: Browser.this.progress.setVisibility(View.GONE);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView webview, String url) {

        webview.loadUrl(url);
        return true;
    }
}

这篇关于电话能见度OnPageFinished - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 02:28