Get the App
SLTechnology News&Howtos  ›  Development  › 

Call loadData () method in Android to show how to solve garbled code.

Shulou Source: shulou.com Published: 2022-06-01 00:17:17 09月11日 Update

This article mainly introduces "how to solve the garbled code called loadData() method in Android". In daily operation, I believe many people have doubts about how to solve the garbled code called loadData() method in Android. Xiaobian consulted all kinds of information and sorted out simple and easy to use operation methods. I hope to answer the doubts of "how to solve garbled code called loadData() method in Android"! Next, please follow the small series to learn together!

Android solves the problem that WebView calls loadData() method to display garbled characters

Step 1:

mWebView.getSettings().setDefaultTextEncodingName("UTF-8");

Step 2:

mWebView.loadData(data, "text/html; charset=UTF-8", null);

WebView common configuration:

private void initWebView() { mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); mWebView.getSettings().setDefaultTextEncodingName("UTF-8"); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); mWebView.getSettings().setSupportZoom(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setAllowFileAccess(true); mWebView.getSettings().setUseWideViewPort(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setLoadWithOverviewMode(true); mWebView.requestFocus(); mWebView.loadUrl(url); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return super.shouldOverrideUrlLoading(view, url); } @Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); } @Override public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) { }; @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); } }); } At this point, the study of "how to solve the garbled code by calling the loadData() method in Android" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Methods random codes learning more questions UTF-8 help practical next commonly used articles theories knowledge articles websites materials follow easy to use practice solutions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei macOS MariaDB Shulou Information