webView网页部分加载控件

源生页面中嵌入HTML5页面  是现在经常见到的 

现摘出自定义WebView模块,供大家参考。



import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class PPWebView extends WebView{

     private WebView mWebView;
     private Context mContext;

     public PPWebView(Context context, AttributeSet attrs) {
          super(context, attrs);
          this.mContext=context;
          mWebView=this;
          initView();
         
     }

     private Dialog dialog;
    
     public static interface OnLoadFinish{
          void onFinish();
     }
     private void initView(){
          WebSettings settings= mWebView.getSettings();
          settings.setUseWideViewPort(true);
          settings.setLoadWithOverviewMode(true);
          settings.setSupportMultipleWindows(true);
          settings.setSupportZoom(true);
          settings.setJavaScriptEnabled(true);
          settings.setPluginState(PluginState.ON);
          settings.setJavaScriptCanOpenWindowsAutomatically(true);
          settings.setAllowFileAccess(true);
          settings.setDefaultTextEncodingName("UTF-8");
          //mWebView.addJavascriptInterface(this, "android");
          mWebView.setBackgroundColor(0);
//          settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
          mWebView.getSettings().setLoadsImagesAutomatically(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
          mWebView.getSettings().setBlockNetworkImage(false);
          mWebView.setWebViewClient(new WebViewClient(){
               @Override
               public void onReceivedError(WebView view, int errorCode,
                         String description, String failingUrl) {
                    //super.onReceivedError(view, errorCode, description, failingUrl);
                    mWebView.loadUrl(" file:///android_asset/neterror.html");
                    //Toast.makeText(mContext, "设置???载失败页", 1).show();
               }
               public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    // TODO Auto-generated method stub
                    super.onPageStarted(view, url, favicon);
               }
              
               @Override
               public void onPageFinished(WebView view, String url) {
                    // TODO Auto-generated method stub
                    super.onPageFinished(view, url);
               }
          });
              
     }
    
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
          if(keyCode==KeyEvent.KEYCODE_BACK && mWebView.canGoBack()){
               mWebView.goBack();
               //return true;
          }
          return super.onKeyDown(keyCode, event);
     }
}


调用同其他自定义组件

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值