androidwebview设置内容的字体⼤⼩
Enum for specifying the text size. SMALLEST is50% SMALLER is75% NORMAL is100% LARGER is150% LARGEST is200% /**
* webview
*/
WebView wv;
/**
* Manages settings state for a WebView
*/
WebSettings settings;
/**
* ⽤来控制字体⼤⼩
*/
int fontSize = 1;
wv = (WebView) findViewById(R.id.webViewContent);
settings = wv.getSettings();
settings.setSupportZoom(true);
if (TextSize() == WebSettings.TextSize.SMALLEST) {
fontSize = 1;
} else if (TextSize() == WebSettings.TextSize.SMALLER) {
fontSize = 2;
} else if (TextSize() == WebSettings.TextSize.NORMAL) {
webview是什么东西fontSize = 3;
} else if (TextSize() == WebSettings.TextSize.LARGER) {
fontSize = 4;
} else if (TextSize() == WebSettings.TextSize.LARGEST) {
fontSize = 5;
}
/**
* 设置底部按钮的事件
*/
private void setImageViewClick() {
/**
* 缩⼩按钮
*/
imgViewSX.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
fontSize--;
if (fontSize < 0) {
fontSize = 1;
}
switch (fontSize) {
case1:
settings.setTextSize(WebSettings.TextSize.SMALLEST);
break;
case2:
settings.setTextSize(WebSettings.TextSize.SMALLER);
break;
case3:
settings.setTextSize(WebSettings.TextSize.NORMAL);
break;
case4:
settings.setTextSize(WebSettings.TextSize.LARGER);
break;
case5:
settings.setTextSize(WebSettings.TextSize.LARGEST);
break;
}
}
});
/**
* 放⼤按钮
*/
imgViewFD.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
fontSize++;
if (fontSize > 5) {
fontSize = 5;
}
switch (fontSize) {
case1:
settings.setTextSize(WebSettings.TextSize.SMALLEST);
break;
case2:
settings.setTextSize(WebSettings.TextSize.SMALLER);
break;
case3:
settings.setTextSize(WebSettings.TextSize.NORMAL);
break;
case4:
settings.setTextSize(WebSettings.TextSize.LARGER);
break;
case5:
settings.setTextSize(WebSettings.TextSize.LARGEST);
break;
}
}
});
final String mimeType = "text/html";
final String encoding = "UTF-8";
content = getContentFromNewWork(newsId);
wv.loadDataWithBaseURL("", content, mimeType, encoding, "");
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论