zoukankan      html  css  js  c++  java
  • WebView的最简单使用

    layout下 :


    webviewdemo.xml 文件


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


    </LinearLayout>

    assets下 :

    demo.html 文件

    ?
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>这是一个HTML</title>


    </head>
    <body>
    <br>
    <br>大家晚上好
    <br>
    <br>大家晚上好
    <br>
    <br>大家晚上好
    <br>


    <input type="button" value="测试" onclick="javascript:window.handler.show(document.body.innerHTML);" />
    </body>
    </body>
    </html>


    Java文件


    WebViewDemo.java文件


    package com.yw.webkitdemo;

    import com.example.hhh.R;

    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.os.Bundle;
    import android.os.Handler;
    import android.webkit.WebSettings;
    import android.webkit.WebSettings.LayoutAlgorithm;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Toast;

    public class WebViewDemo extends Activity {
    private WebView mWebView;

    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.webviewdemo);
    mWebView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = mWebView.getSettings();

    /**
    * 如果是像上面加载百度的url的话,需要设置是否支持JavaScript,
    * 如果不支持JavaScript的话就会启动手机自带的浏览器去加载你要加载的URL, 否则会自己加载。设置是否支持JavaScript的
    */
    webSettings.setJavaScriptEnabled(true);

    // 设置默认加载的可视范围是大视野范围
    webSettings.setLoadWithOverviewMode(true);

    // 加载本地asset文件
    mWebView.loadUrl("file:///android_asset/demo.html");


    // 加载非本地url
    // mWebView.loadUrl("http://www.baidu.com.cn/");

    }
    }


    注意修改Androidmanifest.xml

    文章转载于网络,如有侵权,请原创留言;内容如有不妥,请各位园友提宝贵意见或建议。所有文章均处于编辑状态。。。。。。百度贴吧:流水小桥吧 如有问题,请点击页面左上角“给我写信”发邮件留言!
  • 相关阅读:
    Node快速安装
    PHP实现简单的监控nginx日志文件功能
    解决linux crontab PHP fgetcsv 读取中文数据为空问题
    Linux查看系统信息命令汇总
    分享一个Mongodb PHP封装类
    Redis PHP通用类
    ubuntu安装php mcrypt扩展
    終端機的環境設定: stty, set
    MySQL Got fatal error 1236原因和解决方法
    bash 的進站與歡迎訊息: /etc/issue, /etc/motd
  • 原文地址:https://www.cnblogs.com/flyoung/p/4703982.html
Copyright © 2011-2022 走看看