亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

如何使用webview加載一個本地的Html文件

標簽:
Android

这个功能对于展示app的使用帮助是很有帮助的

https://img1.sycdn.imooc.com//5c0cdaf800019f6106381114.jpg

核心代码:

 private void initView() {
        mWebView = (WebView) findViewById(R.id.load_webView);
        mProgressBar = (ProgressBar) findViewById(R.id.load_progressBar);
        mLoadingLayout = (RelativeLayout) findViewById(R.id.loading_layout);
        mPrompt = (TextView) findViewById(R.id.prompt);
        mNoInternetImageView = (ImageView) findViewById(R.id.no_internet_img);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setLoadsImagesAutomatically(true);
        webSettings.setUseWideViewPort(true);
        //   webSettings.setBuiltInZoomControls(true);
        mWebView.requestFocus();
        mWebView.loadUrl("file:///android_asset/software_licenses.html");
        initWebViewListener();


    }

    private void initWebViewListener() {
//            this.mWebView.setWebViewClient(new WebViewClient() {
//        });

        this.mWebView.setWebChromeClient(new WebChromeClient() {

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress >= 80) {
                    mWebView.setVisibility(View.VISIBLE);
                }
            }
        });

    }

本地的html文件是:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="HandheldFriendly" content="true"/>
    <meta http-equiv="Cache-control" content="no-cache"/>
    <title>Software License</title>
    <style>
        .box { overflow:hidden; width:96%; margin: 0 auto; padding-top: 20px;}
        .lan { overflow:hidden; margin-bottom:20px; color:#2f2f2f; background-color:#eee;}
        h1,
        h2,
        h3,
        h4,
        h5,
        h6,
        p,
        blockquote {
        margin: 0;
        padding: 0;
        text-align: left;
        }
        body {
        font-family: sans, Arial, sans-serif;
        font-size: 13px;
        line-height: 18px;
        color: #2f2f2f;
        background-color: white;
        margin:0;
        padding: 0;
        text-align: center;
        }
        a {
        color: #0069d6;
        }
        a:hover {
        color: #0050a3;
        text-decoration: none;
        }
        a img {
        border: none;
        }
        p {
        overflow:hidden;
        padding:10px 0 0 10px;
        margin-bottom: 9px;
        }
        h1 {
        margin-bottom: 18px;
        font-size: 18pt;
        text-decoration:underline;
        }
        h2 {
        font-size: 24px;
        }
        h3 {
        font-size: 18px;
        }
        h4 {
        font-size: 20px;
        }
        h5 {
        font-size: 14px;
        }
        h6 {
        font-size: 13px;
        }
        hr {
        margin: 0 0 19px;
        border: 0;
        border-bottom: 1px solid #ccc;
        }
        ol, ul { margin:0 10px 0 0; text-align: left;}
        li { text-align: left;}

        /*
        @media screen and (min-width: 914px) {
        body {
        width: 854px;
        margin:10px auto;
        }
        }
        @media print {
        body,code,pre code,h1,h2,h3,h4,h5,h6 {
        color: black;
        }
        table, pre {
        page-break-inside: avoid;
        }
        }
        */
    </style>
</head>
<body>
<div class="box">

<h1>
    apache-mime4j
</h1>

<div class="lan">
    <p>
        Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.
    </p>

    <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
        with the License. You may obtain a copy of the License at </p>

    <p>http://www.apache.org/licenses/LICENSE-2.0</p>

    <p>Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
        on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
        for the specific language governing permissions and limitations under the License.</p>

</div>

<h1>
    bcprov-jdk15on
</h1>

<div class="lan">
    <p>
        Copyright © 2000 - 2013 The Legion of the Bouncy Castle Inc. (http://www.bouncycastle.org)
    </p>

    <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
        documentation files (the "Software"), to deal in the Software without restriction, including without limitation
        the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
        to permit persons to whom the Software is furnished to do so, subject to the following conditions: </p>

    <p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of
        the Software.</p>

    <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
        THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
        CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
        DEALINGS IN THE SOFTWARE.</p>

</div>

</div>
</body>
</html>

代码在https://github.com/nickgao1986/StepSport

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消