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: 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í)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python 如何在 Matplotlib 中繪制垂直線2. bootstrap select2 動(dòng)態(tài)從后臺(tái)Ajax動(dòng)態(tài)獲取數(shù)據(jù)的代碼3. ASP常用日期格式化函數(shù) FormatDate()4. python中@contextmanager實(shí)例用法5. html中的form不提交(排除)某些input 原創(chuàng)6. CSS3中Transition屬性詳解以及示例分享7. js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼8. 如何通過(guò)python實(shí)現(xiàn)IOU計(jì)算代碼實(shí)例9. 開(kāi)發(fā)效率翻倍的Web API使用技巧10. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式
