受不了Android SDK文檔開啟緩慢問題,自己開發簡易離線瀏覽器。

來源:互聯網
上載者:User

受不了Android SDK文檔開啟緩慢問題,自己開發簡易離線瀏覽器。

google android sdk離線文檔開啟的時候特別慢,據說是要從Google官網拉取一些東西導致的。離線瀏覽可以解決該問題。PC端可以使用firefox。

但是Android端貌似沒有支援離線工作的瀏覽器。這讓我很傷心。決定開發一個簡易的離線瀏覽器以便在手機端快速查看sdk文檔。

設計到的知識點主要為:WebView的初始化以及縮放問題;將應用程式添加到檔案開啟檔案中。

廢話不多說:以下為代碼部分:

MainActivity:

package net.xby1993.simpleexplorer;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.KeyEvent;import android.view.Window;import android.view.WindowManager;import android.webkit.WebChromeClient;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient;public class MainActivity extends Activity {    private static final String TAG=MainActivity.class.getSimpleName();    private WebView webView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //設定全屏無標題列        requestWindowFeature(Window.FEATURE_NO_TITLE);        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);        setContentView(R.layout.activity_main);        webView = (WebView)findViewById(R.id.webView);        WebSettings settings= webView.getSettings();        //開啟縮放支援        settings.setSupportZoom(true);        settings.setBuiltInZoomControls(true);        settings.setJavaScriptEnabled(true);        //預設對縮放比例有限制,導致使用者體驗不好,所以需要設定為使用任意比例縮放。        settings.setUseWideViewPort(true);        //使頁面之間可以點選連結導航        webView.setWebViewClient(new WebViewClient());        webView.setWebChromeClient(new WebChromeClient());        //初始頁面一般過大,我們設定為75%        webView.setInitialScale(75);        Intent intent=getIntent();        //提取檔案管理工具開啟檔案傳送的檔案地址        if(intent.getAction().equals(Intent.ACTION_VIEW)){            String strUri=intent.getDataString();            Log.d(TAG,TAG);            Log.d(TAG,strUri);            Log.d(TAG,Uri.encode(strUri));            webView.loadUrl(strUri);        }    }    @Override    public boolean onKeyDown(int keyCode,KeyEvent event){        //確保可以通過返回鍵瀏覽曆史頁面棧        if(keyCode==event.KEYCODE_BACK&&webView.canGoBack()){            webView.goBack();            return true;        }        return super.onKeyDown(keyCode,event);    }}

AndroidManifest.xml

                                                                                                                                                                                    




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.