最近开发app,发现需要用webview加载html代码块,需要将服务端返回的代码块转换为可以通过webview加载的数据,例如:
Our Growing Tomatoes Guide covers everything from planting through harvesting! Tomatoes are not hard to grow; they’re incredibly productive, versatile in the kitchen, and so delicious off the vine. Our guide covers all the information you need to grow tomatoes successfully—including selecting tomato varieties, starting seeds, transplanting tomatoes outside, using tomato stakes and cages, and tomato plant care.
Tomatoes are long-growing, heat-seeking, sun lovers! These warm-season plants do not tolerate frost. In most regions, the soil is not warm enough until April or May, but it depends on where you live.
HOW LONG DOES IT TAKE TO GROW A TOMATO?
This is one of our most common questions. The days to harvest depends on the cultivar, but the days to maturity ranges from 60 days to more than 80 days.
Due to a relatively long growing season, tomatoes are most commonly transplanted rather than direct-seeded into the garden. Transplants can be purchased in garden nurseries. Look for short, stocky plants with dark green color and straight, sturdy stems about the size of a pencil or thicker. Avoid plants with yellowing leaves, spots, or stress damage; avoid plants with flowers or fruits already in progress.
TYPES OF TOMATOES
Tomatoes are available in a wide variety of sizes, from tiny grape-size types to giant beefstakes. The choice also depends on how you will use this verstaile fruit in the kitchen. For example, Roma tomatoes are not very good eaten fresh, but are well suited for sauces and ketchups. Tomato cultivars can be classified according to their growth habit:
Determinate tomatoes are plants that grow to pre-determined height. They are good choices for canning and sauce-making.
Indeterminate tomatoes increase in height throughout the growing season because the terminal of the stem continues to produce foliar growth rather than set flowers. The fruits on these plants are produced continually through the season along the side shoots of the plant. Indeterminate tomatoes are the choice if you want to spread out the harvest over a longer period of time.
Tomatoes do need vigilant care, as the crop is susceptible to pests and diseases. To avoid problems, choose disease-resistant cultivars whenever possible. Also, note that tomato plants will be more susceptible to soil-borne disease and rot if not kept off the ground with a stake or other support system. We’ll cover all these essentials in the tomato guide below.
转换函数:
???public?static?String?getHtmlData(String?bodyHTML)?{ ????????String?head?=?""?+ ????????????????""?+ ????????????????""?+ ????????????????""; ????????return?""?+?head?+?""?+?bodyHTML?+?""; ????} ????//如果width:100%,则显示的图片是填充状态,设置auto图片显示很小
webview设置:
?WebSettings?settings?=?mWebView.getSettings(); ????????settings.setTextZoom(450);//设置字体大小 ????????settings.setJavaScriptCanOpenWindowsAutomatically(true);?//?设置JS是否可以打开WebView新窗口 ????????settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); ????????settings.setSupportZoom(true);?//?支持缩放 ????????settings.setBuiltInZoomControls(true);?//?支持手势缩放 ????????settings.setDatabaseEnabled(true);//数据库存储API是否可用,默认值false。 ????????settings.setSaveFormData(true);//WebView是否保存表单数据,默认值true。 ????????settings.setDomStorageEnabled(true);//DOM存储API是否可用,默认false。 ????????//190925 ????????settings.setBlockNetworkImage(false);//解决图片不显示 ????????settings.setUseWideViewPort(true);?//?将图片调整到适合WebView的大小 //????????settings.setLoadWithOverviewMode(true);?//?自适应屏幕 ????????if?(Build.VERSION.SDK_INT?>?Build.VERSION_CODES.LOLLIPOP)?{ ????????????settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); ????????} ????????mWebView.setHorizontalScrollBarEnabled(false);//去掉webview的滚动条,水平不显示 ????????mWebView.setScrollbarFadingEnabled(true); ????????//20190918 ????????mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); ????????mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);?//?取消WebView中滚动或拖动到顶部、底部时的阴影
然后就可以完美展示了~~
注意,当使用webview加载时,系统8.1以上加载会失败,
可以使用:mWebView.loadDataWithBaseURL(null,html, "text/html;charset=utf-8", "utf-8",null);