zoukankan      html  css  js  c++  java
  • Android webView输出自定义网页

    这次来使用webview输出网页型数据。因为这样的数据好使用富文本编辑器,有各种各样的拓展。

    上代码:

    package controller.hzl.com.testcall;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
        private WebView webView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            String webs = ""<!DOCTYPE html>
    " +
                    "<html>
    " +
                    "<head>
    " +
                    "<meta charset="utf-8">
    " +
                    "<title>hello tomcat</title>
    " +
                    "</head>
    " +
                    "<body>
    " +
                    "    <h1>1</h1>
    " +
                    "    <p>2</p>" +
                    "tel:13800138000" +
                    "</body>
    " +
                    "</html>"" ;
    
            webView = (WebView) findViewById( R.id.webview );
    
            //webview
            webView.loadDataWithBaseURL( null, webs , "text/html", "UTF-8", null ) ;
    
    
        }
    
    
     
    }

    页面代码:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".MainActivity">
    
        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </WebView>
    
    </RelativeLayout>

    这里提示一点,如果想要拿网页进行显示的话,需要加一行代码,不然显示不了。

        </application>
        <uses-permission android:name="android.permission.INTERNET" />

    代码完毕,放结果:

  • 相关阅读:
    CLR基础
    Windows7下使用Shell32.dll出现没有实现接口的错误的解决办法
    Python学习
    Python学习
    开发常识之Linux用户及其权限管理
    (转)简单明晰的Jupyter Notebook总结与指南
    Oracle系列数据库版本区别
    应用场景区别-MongoDB与MySQL的选择比较
    我的博客(个人空间)地址更新说明
    (转)Spark与Map-Reduce区别对比
  • 原文地址:https://www.cnblogs.com/sunxun/p/9288352.html
Copyright © 2011-2022 走看看