2

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

1 Answer 1

3

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:

Sign up to request clarification or add additional context in comments.

2 Comments

thx for your answer,but I only want to load CSS and JS not the entire website.
i didn't get you , you need to load js and css to A page already exists in webview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.