简体   繁体   中英

Load CSS and JS files from assets folder in android webview

I want to load CSS and JS files localy from android assets folder for better perfomance in android webview,Is it possible? I appreciate your help,thanks

In android project

WebView myweb = FindViewById<WebView>(Resource.Id.webView1);
myweb.LoadUrl("file:///android_asset/index.html");

In index.html

<link href="style.css" rel="stylesheet" type="text/css">
<script src="script.js"></script> 

And if you need to increase android webview performance and graphic change this properties

myweb.Settings.JavaScriptEnabled = true;
myweb.Settings.DisplayZoomControls = false;
myweb.Settings.SetRenderPriority(WebSettings.RenderPriority.High);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
   myweb.SetLayerType(Android.Views.LayerType.Hardware, null);
}

if you are using android studio : view this link

if you need only js or css files view this Answers:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM