欢迎来到代码驿站!

当前位置:首页 >

Android webView如何输出自定义网页

时间:2020-09-23 11:00:26|栏目:|点击:

这次来使用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>\n" +
        "<html>\n" +
        "<head>\n" +
        "<meta charset=\"utf-8\">\n" +
        "<title>hello tomcat</title>\n" +
        "</head>\n" +
        "<body>\n" +
        "  <h1>1</h1>\n" +
        "  <p>2</p>" +
        "tel:13800138000" +
        "</body>\n" +
        "</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" />

代码完毕,放结果:

上一篇:Spring mvc服务端数据校验实现流程详解

栏    目:

下一篇:R语言ggplot2边框背景去除的实现

本文标题:Android webView如何输出自定义网页

本文地址:http://www.codeinn.net/misctech/5320.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有