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>\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" />

代码完毕,放结果:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值