这次来使用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 = "\"\n" +

"\n" +

"

\n" +

"\n" +

"

hello tomcat\n" +

"\n" +

"

\n" +

"

1

\n" +

"

2

" +

"tel:13800138000" +

"\n" +

"\"" ;

webView = (WebView) findViewById( R.id.webview );

//webview

webView.loadDataWithBaseURL( null, webs , "text/html", "UTF-8", null ) ;

}

}

页面代码:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true"

tools:context=".MainActivity">

android:id="@+id/webview"

android:layout_width="match_parent"

android:layout_height="match_parent">

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

代码完毕,放结果:

c583a026b6441f5bf67daa5c3393c120.png

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

时间: 2020-09-20

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐