public class ZX_Activity extends BaseActivity implements IContract.IMainZXView {
@BindView(R.id.webview_id)
WebView webviewId;
@Override
public void success(ZX_Bean bean) {
//时间转换
long releaseTime = result.getReleaseTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
long releaseTime1 = result.getReleaseTime();
String format = simpleDateFormat.format(releaseTime1);
timeId.setText(format);
String content = bean.getResult().getContent();
if (content.contains("http:http")) {
content = content.replaceAll("http:http", "http");
}
WebSettings settings = webviewId.getSettings();
settings.setJavaScriptEnabled(true);
webviewId.setWebViewClient(new ArticleWebViewClient());
// webviewId.seth
webviewId.loadDataWithBaseURL(null,content,"text/html","utf-8",null);
}
@Override
protected int getLayout() {
return R.layout.activity_z_x;
}
@Override
protected ZXPresenter initPresenter() {
return new ZXPresenter();
}
@Override
protected void initData() {
Intent intent = getIntent();
int infoId = intent.getIntExtra("infoId", 0);
getPresenter().loadDate(infoId);
}
private static class ArticleWebViewClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//重置webview中img标签的图片大小
imgReset(view);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
//对图片进行重置大小,宽度就是手机屏幕宽度,高度根据宽度比便自动缩放
private static void imgReset(WebView webView) {
webView.loadUrl("javascript:(function(){" + "var objs = document.getElementsByTagName('img'); " +
"for(var i=0;i<objs.length;i++) " + "{" + "var img = objs[i]; " +
" img.style.maxWidth = '100%'; img.style.height = 'auto'; " + "}" + "})()");
}
}