欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

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

程序员文章站 2024-01-31 22:27:04
...
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 
* 描述:
* 创建者: lidongdong
* 创建日期:2015-8-16 * 版本:
* 修改者:
* 修改日期: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 = ""; 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 = "

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

"; // 加载本地css 不行 不能读取// linkCss = ""; html = "
" + linkCss + "
" + content + "