>웹 프론트엔드 >HTML 튜토리얼 >webview 中使用css适配简单的页面_html/css_WEB-ITnose

webview 中使用css适配简单的页面_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-24 11:38:451352검색

package com.example.mycssdemo;import android.annotation.SuppressLint;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.Menu;import android.webkit.WebSettings;import android.webkit.WebSettings.LayoutAlgorithm;import android.webkit.WebView;import android.webkit.WebViewClient;/** * 类名:MainActivity.java <br> * 描述: <br> * 创建者: lidongdong <br> * 创建日期:2015-8-16 * 版本: <br> * 修改者:<br> * 修改日期:2015-8-16 */@SuppressLint("SetJavaScriptEnabled")public class MainActivity extends Activity {	private WebView mWebView;	private WebSettings mWebSetting;	private String content;	private String linkCss;	private String html;		@Override	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setContentView(R.layout.activity_main);		mWebView= (WebView) findViewById(R.id.web_view);		mWebSetting = mWebView.getSettings();		mWebSetting.setJavaScriptEnabled(true);		//======================保证页面的完整显示在手机屏幕上=======================		mWebSetting.setUseWideViewPort(true); 		mWebSetting.setLoadWithOverviewMode(true); 				mWebSetting.setSupportZoom(true);  		mWebSetting.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);  		mWebSetting.setJavaScriptEnabled(true); //		mWebView.loadUrl("http://news.dahe.cn/2015/08-11/105436453.html");		linkCss = "<style type='\"text/css\"'> img {" +				"width:100%;" +				"height:auto;" +				"}" +				"body {" +				"margin-right:15px;" +				"margin-left:15px;" +				"margin-top:15px;" +				"font-size:45px;" +				"}" +				"</style>";		mWebView.setWebViewClient(new WebViewClient(){						@Override			public boolean shouldOverrideUrlLoading(WebView view, String url) {				Log.i("DD", "======="+url);//				mWebView.loadData(linkCss, "text/html", "utf-8");				view.loadUrl(url);				return true;			}		});				content = "<p><img  src="%5C%22http://img5.imgtn.bdimg.com/it/u=3572074785,265614668&fm=21&gp=0.jpg%5C%22" alt="webview 中使用css适配简单的页面_html/css_WEB-ITnose" >hahahha</p>";				// 加载本地css 不行 不能读取//		linkCss = "<link rel='\"stylesheet\"' href="%5C%22file:///android_asset/img.css%5C%22" type='\"text/css\"'>";				html = "<header>" + linkCss + "</header>" + content + "
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.