zoukankan      html  css  js  c++  java
  • Android自定义的webView——可实现的网页文本的复制

    package com.example.customlinearlayout.view;
    
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.view.View;
    import android.webkit.JsResult;
    import android.webkit.WebChromeClient;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Toast;
    
    public class LiveWebView extends WebView {
    
        Context mContext;
    
        public LiveWebView(Context context) {
            super(context);
            mContext = context;
            setWebViewClient();
        }
    
        public LiveWebView(Context context, AttributeSet attrs) {
            super(context, attrs);
            mContext = context;
            setWebViewClient();
        }
    
        @Override
        public boolean onCheckIsTextEditor() {
            return true;
        }
    
        boolean setWebViewClient() {
    
            setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
            setFocusable(true);
            setFocusableInTouchMode(true);
            requestFocus(View.FOCUS_DOWN);
            WebSettings webSettings = getSettings();
            webSettings.setSavePassword(false);
            webSettings.setSaveFormData(false);
            webSettings.setJavaScriptEnabled(true);
            webSettings.setSupportZoom(false);
            webSettings.setUseWideViewPort(true);
    
            setOnTouchListener(new View.OnTouchListener() {
    
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_UP:
                        if (!v.hasFocus()) {
                            v.requestFocus();
                        }
                        break;
                    }
                    return false;
                }
    
            });
    
            this.setWebViewClient(new WebViewClient() {
                ProgressDialog dialog = new ProgressDialog(mContext);
    
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    System.out.println("+-------------------------------");
                    System.out.println("|    shouldOverrideUrlLoading : url:  " + url);
                    System.out.println("+-------------------------------");
                    loadUrl(url);
    
                    return true;
                }
    
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                    Toast.makeText(mContext, "Oh no! " + description, Toast.LENGTH_SHORT).show();
                }
    
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    if (dialog != null) {
                        dialog.setMessage("Loading...");
                        dialog.setIndeterminate(true);
                        dialog.setCancelable(true);
                        dialog.show();
                    }
                }
    
                public void onPageFinished(WebView view, String url) {
                    if (dialog != null) {
                        dialog.cancel();
                    }
                }
            });
    
            this.setWebChromeClient(new WebChromeClient() {
                public void onProgressChanged(WebView view, int progress) {
                }
    
                @Override
                public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
                    System.out.println("+-------------------------------");
                    System.out.println("|WebChromeClient onJsAlert    " + message);
                    System.out.println("+-------------------------------");
                    result.confirm();
                    return true;
                }
            });
    
            loadUrl("http://www.baidu.com");
    
            return true;
        }
    
    }
  • 相关阅读:
    iOS 10 的一个重要更新-用 UIViewPropertyAnimator 编写动画
    iOS 10 的一个重要更新-线程竞态检测工具 Thread Sanitizer
    iOS 10 的一个重要更新-开发 iMessage 的第三方插件
    状态栏白色
    iOS 对 HTTPS 证书链的验证
    Xcode8 带来的新特性和坑
    升级cocoapods1.1.1版本
    (这也不是,那也不是,怎么办?)无论何时坚持自己的原则,当选准了目标,就不放弃,做最好的自己。我们必须要有一定的看法,正确的做法;有时,我们无法避免他人在旁的批评或劝告,但我们是无法取悦每个人的,否则将失去了方向,迷失了自己。
    笑话集锦(1)
    最感动的一首现代诗(转)(修正了一点翻译)
  • 原文地址:https://www.cnblogs.com/hsx514/p/3670077.html
Copyright © 2011-2022 走看看