webview使用实例,解决加载本地html代码乱码问题

descriptionView.loadData(data.description, "text/html", "utf-8");在有些手机上会出现乱码,将方法变成descriptionView.loadDataWithBaseURL(null,data.description, "text/html", "utf-8",null);就可以解决这个问题。

例子:

//详细内容,显示的是html的内容;

WebView descriptionView=(WebView) this.findViewById(R.id.description);
WebSettings ws = descriptionView.getSettings();
ws.setJavaScriptEnabled(false);
ws.setAllowFileAccess(true); 
ws.setBuiltInZoomControls(false);
ws.setSupportZoom(false);  

/**
*  设置网页布局类型:
*  1、LayoutAlgorithm.NARROW_COLUMNS : 适应内容大小
*  2、LayoutAlgorithm.SINGLE_COLUMN: 适应屏幕,内容将自动缩放
*
*/

ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
ws.setDefaultTextEncodingName("utf-8"); //设置文本编码
ws.setAppCacheEnabled(true);
ws.setCacheMode(WebSettings.LOAD_DEFAULT);//设置缓存模式</span>        
descriptionView.loadDataWithBaseURL(null,data.description, "text/html", "utf-8",null);
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值