zoukankan      html  css  js  c++  java
  • android浏览器开发小技巧集锦(转)

    本人和朋友们做了一段时间浏览器,将一些小技巧分享出来,先写一部分,慢慢写,同时也为我们的浏览器打打广告

    我们的浏览器将要上线,名叫沙发浏览

    1.网页内的右键菜单

    [java] view plaincopy
     
    1. public boolean onLongClick(View view) {  
    2.         // 获取点击的元素  
    3.         HitTestResult mResult = mWebView.getHitTestResult();  
    4.   
    5.         final int type = mResult.getType();  
    6.         switch (type) {  
    7.             case HitTestResult.ANCHOR_TYPE:  
    8.             case HitTestResult.SRC_ANCHOR_TYPE:  
    9.                 //点击的是链接  
    10.                 break;  
    11.   
    12.             case HitTestResult.IMAGE_TYPE:  
    13.             case HitTestResult.IMAGE_ANCHOR_TYPE:  
    14.             case HitTestResult.SRC_IMAGE_ANCHOR_TYPE:  
    15.                 //点击的是图片  
    16.                 break;  
    17.   
    18.             default:  
    19.                 //点击的是空白处  
    20.                 break;  
    21.         }  
    22.         return true;  
    23.     }  

    根据是图片还是链接还是空白做判断

    2.网页内的自由复制

    转载请注明出处:http://blog.csdn.net/ethan_xue/article/details/7748075

    [java] view plaincopy
     
    1. /** 
    2.      * 网页里 复制粘贴 
    3.      * @param view webView 
    4.      * @author ethan 
    5.      */  
    6.     private void emulateShiftHeld(KeyEvent.Callback view)  
    7.     {  
    8.         try  
    9.         {  
    10.             KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,  
    11.                     KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);  
    12.             shiftPressEvent.dispatch(view);  
    13.         } catch (Exception e)  
    14.         {  
    15.         }  
    16.     }  

    3.出错界面

    webkit自带的出错界面不够霸气,于是改为自己做的出错界面

    [java] view plaincopy
     
    1. new WebViewClient()  
    2. ...此为背景  
    3. @Override  
    4.         public void onReceivedError(WebView view, int errorCode,  
    5.                 String description, String failingUrl) {  
    6.             view.stopLoading();  
    7.             view.clearView();  
    8.   
    9.             // 显示出错界面  
    10.             mWebView.loadUrl("file:///android_asset/error.html");  
    11.         }  

    4.点外部链接调用自己的浏览器

    在manifest.xml里主activity加入intent

    [html] view plaincopy
     
    1. <style="color: rgb(51, 51, 51); font-family: Arial; font-size: 16px; line-height: 25px; text-align: left; "><!-- For these schemes were not particular MIME type has been  
    2.                  supplied, we are a good candidate. -->  
    3.             <intent-filter>  
    4.                 <action android:name="android.intent.action.VIEW" />  
    5.                 <category android:name="android.intent.category.DEFAULT" />  
    6.                 <category android:name="android.intent.category.BROWSABLE" />  
    7.                 <data android:scheme="http" />  
    8.                 <data android:scheme="https" />  
    9.                 <data android:scheme="about" />  
    10.                 <data android:scheme="javascript" />  
    11.             </intent-filter>  
    12.             <!--  For these schemes where any of these particular MIME types  
    13.                   have been supplied, we are a good candidate. -->  
    14.             <intent-filter>  
    15.                 <action android:name="android.intent.action.VIEW" />  
    16.                 <category android:name="android.intent.category.BROWSABLE" />  
    17.                 <category android:name="android.intent.category.DEFAULT" />  
    18.                 <data android:scheme="http" />  
    19.                 <data android:scheme="https" />  
    20.                 <data android:scheme="inline" />  
    21.                 <data android:mimeType="text/html"/>  
    22.                 <data android:mimeType="text/plain"/>  
    23.                 <data android:mimeType="application/xhtml+xml"/>  
    24.                 <data android:mimeType="application/vnd.wap.xhtml+xml"/>  
    25.             </intent-filter>  
    26.                 <action android:name="android.intent.action.VIEW" />  
    27.                 <category android:name="android.intent.category.DEFAULT" />  
    28.                 <category android:name="android.intent.category.BROWSABLE" />  
    29.                 <data android:scheme="file" />  
    30.             </intent-filter></p>  

    外部调用就ok了,连file文件都能调用,若自己调用的话

    [java] view plaincopy
     
    1. Uri uri = Uri.parse("file://data/data/test.html");  
    2. //   Uri uri = Uri.parse("http://m.baidu.com");       
    3.   Intent it = new Intent(Intent.ACTION_VIEW, uri);          
    4.   context.startActivity(it);       


    http://blog.csdn.net/ethan_xue/article/details/7748075

  • 相关阅读:
    redis+Keepalived实现Redis主从复制
    Python基础之【第一篇】
    Django之常用命令以及问题汇总
    Django之ORM数据库
    牛掰的python与unix
    Django配置Bootstrap, js
    Django基础教程
    Django安装
    前端学习之jQuery
    centos7安装python3 以及tab补全功能
  • 原文地址:https://www.cnblogs.com/softidea/p/4864072.html
Copyright © 2011-2022 走看看