• 如何给webview页面自定义404页面


    //示例地图类
    package com.can2do.doimobile.news;
    
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.TextView;
    
    import com.can2do.doimobile.R;
    import com.can2do.doimobile.base.BaseUiWeb;
    import com.can2do.doimobile.base.C;
    
    public class UiNewsOne extends BaseUiWeb {
        
        private String tag = null;
        private WebView mWebViewMap;
        
        @Override
        public void onStart() {
            super.onStart();
            
            setContentView(R.layout.ui_news_one);
            
            Bundle params = this.getIntent().getExtras();
            tag = params.getString("tag");
            
            TextView titleText = (TextView) this
                    .findViewById(R.id.main_top_title1);
            titleText.setText(tag);
                    
            mWebViewMap = (WebView) findViewById(R.id.web_news_one);
            mWebViewMap.getSettings().setJavaScriptEnabled(true);
            mWebViewMap.setWebViewClient(new WebViewClient(){
            });
            mWebViewMap.setWebViewClient(new WebViewClient() {
                 public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                 {
                     view.stopLoading();
                     view.clearView();
                     Message msg=handler.obtainMessage();//发送通知,加入线程
                     msg.what=1;//通知加载自定义404页面
                     handler.sendMessage(msg);//通知发送!
                 }
                 public boolean shouldOverrideUrlLoading(WebView view, String url)  
                 {
                     view.loadUrl(url);
                     return true;
                 }
            });
            mWebViewMap.loadUrl(C.news.news1);
            
            this.setWebView(mWebViewMap);
            this.startWebView();
        }
        
         protected Handler handler = new Handler(){
             public void handleMessage(Message message){
                 switch (message.what) {
                 case 1:
                     mWebViewMap.loadUrl("file:///android_asset/www/404/404.html");
                     break;
                 }
             }
         };
             
    }
  • 相关阅读:
    转载Dockerfile 中 RUN, CMD, ENTRYPOINT 的区别
    在linux上通过ssh使用github
    dns服务
    centos6 free 和 centos 7的free 的差异与对比
    无重复字符的最长子串
    go get命令在go mod目录下与正常目录执行的区别
    安装git
    转载 筛子算法之golang实现求素数解析
    Go语言基础之并发
    go之无缓冲channel(通道)和有缓冲channel(通道)
  • 原文地址:https://www.cnblogs.com/huidaoli/p/4212870.html
Copyright © 2020-2023  润新知