Android webView如何輸出自定義網(wǎng)頁(yè)
這次來(lái)使用webview輸出網(wǎng)頁(yè)型數(shù)據(jù)。因?yàn)檫@樣的數(shù)據(jù)好使用富文本編輯器,有各種各樣的拓展。
上代碼:
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 ) ;
}
}
頁(yè)面代碼:
<?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>
這里提示一點(diǎn),如果想要拿網(wǎng)頁(yè)進(jìn)行顯示的話,需要加一行代碼,不然顯示不了。
</application> <uses-permission android:name="android.permission.INTERNET" />
代碼完畢,放結(jié)果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解決android studio卡頓,提升studio運(yùn)行速度的方法
這篇文章主要介紹了解決android studio卡頓,提升studio運(yùn)行速度的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03
Android 中SQLite技術(shù)實(shí)例詳解
這篇文章主要介紹了Android 中SQLite技術(shù)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06
Android SwipeRefreshLayout仿抖音app靜態(tài)刷新
這篇文章主要為大家詳細(xì)介紹了Android SwipeRefreshLayout仿抖音app靜態(tài)刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03
Android編程之微信SDK分享功能過(guò)程步驟詳細(xì)分析
這篇文章主要介紹了Android編程之微信SDK分享功能過(guò)程步驟詳細(xì)分析,較為詳細(xì)的分析了Android微信SDK分享功能的原理、步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2015-10-10
解決Android啟動(dòng)APP的一瞬間系統(tǒng)欄會(huì)變成藍(lán)色問(wèn)題
這篇文章主要介紹了解決Android啟動(dòng)APP的一瞬間系統(tǒng)欄會(huì)變成藍(lán)色問(wèn)題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-06-06

