android瀏覽器開發小技巧集錦

來源:互聯網
上載者:User

本人和朋友們做了一段時間瀏覽器,將一些小技巧分享出來,先寫一部分,慢慢寫,同時也為我們的瀏覽器打打廣告

我們的瀏覽器將要上線,名叫沙發瀏覽

1.網頁內的右鍵菜單

public boolean onLongClick(View view) {// 擷取點擊的元素HitTestResult mResult = mWebView.getHitTestResult();final int type = mResult.getType();switch (type) {case HitTestResult.ANCHOR_TYPE:case HitTestResult.SRC_ANCHOR_TYPE://點擊的是連結break;case HitTestResult.IMAGE_TYPE:case HitTestResult.IMAGE_ANCHOR_TYPE:case HitTestResult.SRC_IMAGE_ANCHOR_TYPE://點擊的是圖片break;default://點擊的是空白處break;}return true;}

根據是圖片還是連結還是空白做判斷

2.網頁內的自由複製

轉載請註明出處:http://blog.csdn.net/ethan_xue/article/details/7748075

/** * 網頁裡 複製粘貼 * @param view webView * @author ethan */private void emulateShiftHeld(KeyEvent.Callback view){try{KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);shiftPressEvent.dispatch(view);} catch (Exception e){}}

3.出錯介面

webkit內建的出錯介面不夠霸氣,於是改為自己做的出錯介面

new WebViewClient()...此為背景@Overridepublic void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {view.stopLoading();view.clearView();// 顯示出錯介面mWebView.loadUrl("file:///android_asset/error.html");}

4.點外部連結調用自己的瀏覽器

在manifest.xml裡主activity加入intent

<!-- For these schemes were not particular MIME type has been                 supplied, we are a good candidate. -->            <intent-filter>                <action android:name="android.intent.action.VIEW" />                <category android:name="android.intent.category.DEFAULT" />                <category android:name="android.intent.category.BROWSABLE" />                <data android:scheme="http" />                <data android:scheme="https" />                <data android:scheme="about" />                <data android:scheme="javascript" />            </intent-filter>            <!--  For these schemes where any of these particular MIME types                  have been supplied, we are a good candidate. -->            <intent-filter>                <action android:name="android.intent.action.VIEW" />                <category android:name="android.intent.category.BROWSABLE" />                <category android:name="android.intent.category.DEFAULT" />                <data android:scheme="http" />                <data android:scheme="https" />                <data android:scheme="inline" />                <data android:mimeType="text/html"/>                <data android:mimeType="text/plain"/>                <data android:mimeType="application/xhtml+xml"/>                <data android:mimeType="application/vnd.wap.xhtml+xml"/>            </intent-filter>                <action android:name="android.intent.action.VIEW" />                <category android:name="android.intent.category.DEFAULT" />                <category android:name="android.intent.category.BROWSABLE" />                <data android:scheme="file" />            </intent-filter>

外部調用就ok了,連file檔案都能調用,若自己調用的話

Uri uri = Uri.parse("file://data/data/test.html");//   Uri uri = Uri.parse("http://m.baidu.com");       Intent it = new Intent(Intent.ACTION_VIEW, uri);          context.startActivity(it);     

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.