安卓webView加载HTML数据

来源:互联网 发布:手机版ps软件 编辑:程序博客网 时间:2024/05/22 04:52
import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.webkit.WebSettings;import android.webkit.WebView;public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        String html="<title>TextView使用HTML</title>";        WebView descriptionView=(WebView) this.findViewById(R.id.Webview);        WebSettings ws = descriptionView.getSettings();        ws.setJavaScriptEnabled(false);        ws.setAllowFileAccess(true);        ws.setBuiltInZoomControls(false);        ws.setSupportZoom(false);        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);        ws.setDefaultTextEncodingName("utf-8"); //设置文本编码        ws.setAppCacheEnabled(true);        ws.setCacheMode(WebSettings.LOAD_DEFAULT);//设置缓存模式</span>        descriptionView.loadDataWithBaseURL(null,html, "text/html", "utf-8",null);    }}
0 0
原创粉丝点击