Android与H5互调之AlerDialog的实现webView网页字体的大小
程序员文章站
2022-06-21 19:15:59
private void getData() { url = getIntent().getStringExtra("url"); //设置支持javaScript webSettings = webview.getSettings(); //设置支持javaScript webSettings.setJavaScriptEnabled(true); //设置算计变大变小 webSettings.setUseWideViewPort(true); ....
private void getData() {
url = getIntent().getStringExtra("url");
//设置支持javaScript
webSettings = webview.getSettings();
//设置支持javaScript
webSettings.setJavaScriptEnabled(true);
//设置算计变大变小
webSettings.setUseWideViewPort(true);
//设置缩放按钮
webSettings.setBuiltInZoomControls(true);
//不让从当前网页跳转到系统的浏览器中
webview.setWebViewClient(new WebViewClient(){
//单加载页面完成时调用
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
pdLoading.setVisibility(View.GONE);
}
});
webview.loadUrl(url);
}
private void getData() {
url = getIntent().getStringExtra("url");
//设置支持javaScript
webSettings = webview.getSettings();
//设置支持javaScript
webSettings.setJavaScriptEnabled(true);
//设置算计变大变小
webSettings.setUseWideViewPort(true);
//设置缩放按钮
webSettings.setBuiltInZoomControls(true);
//不让从当前网页跳转到系统的浏览器中
webview.setWebViewClient(new WebViewClient(){
//单加载页面完成时调用
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
pdLoading.setVisibility(View.GONE);
}
});
webview.loadUrl(url);
}
private void showChangeTextSizeDialog() {
//设置Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("设置文字大小");
String[] items = {"超大字体","大字体","正常字体","小字体","超小字体"};
builder.setSingleChoiceItems(items,realSize,new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
tempSize = which;
}
});
builder.setNegativeButton("取消",null);
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
realSize = tempSize;
changeTextSize(realSize);
}
});
builder.show();
}
private void changeTextSize(int realSize) {
switch (realSize){
case 0://超大字体
webSettings.setTextZoom(200);
break;
case 1://大字体
webSettings.setTextZoom(150);
break;
case 2://正常字体
webSettings.setTextZoom(100);
break;
case 3://小字体
webSettings.setTextZoom(75);
break;
case 4://超小字体
webSettings.setTextZoom(50);
break;
}
}
本文地址:https://blog.csdn.net/weixin_42765222/article/details/107140925