android webview 加载html 第一次字体正常,点击按钮后字体变大

使用android webview 加载html页面,第一次加载的没有问题,点击按钮之后,页面上非
控件的元素字体变大。哪位大神知道这是什么原因?

3个回答

把代码粘贴出来好找原因!

public class MainActivity extends Activity {
private WebView webView;
private long firstTime = 0;
private FrameLayout frame;
private TextView frame_tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
initView();
initWebView();
setWebView();
}

private void setWebView() {
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            frame.setVisibility(View.GONE);
            frame_tv.setVisibility(View.GONE);

            super.onPageFinished(view, url);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            frame.setVisibility(View.GONE);      
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });


    String url = "file:///android_asset/bikemt/login.html";
    webView.loadUrl(url.trim());



}

private void initView(){
    webView = (WebView) findViewById(R.id.webview);
    frame = (FrameLayout)findViewById(R.id.frame);
    frame_tv = (TextView)findViewById(R.id.frame_tv);


}
private void initWebView() {

    WebSettings webSettings = webView.getSettings();

// webView.setInitialScale(1);
webSettings.setSupportZoom(true);
// webSettings.setBuiltInZoomControls(true);
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setJavaScriptEnabled(true);
//不适用缓存只从网络获取数据
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAppCacheEnabled(false);
webSettings.setTextZoom(100);
webSettings.setDefaultFontSize(16);

}

}
第一次显示html页面是正常的,但是点击页面上的按钮,字体变大了

webSettings.setTextZoom(100);
webSettings.setDefaultFontSize(16);
这2句代码删掉就好了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐