简体   繁体   中英

Add HTML code to html file in assets folder using webview

I am working with Android Webview and my html file is in assets directory. I have a href in my html:

<a class='edit link1'></a>

Now, I want to change this code dynamically using my Java code when android button widget is pressed and add some style to it like:

<a class='edit link1' style="border-radius:20px;"></a>

Is it even possible? Thanks in advance.

Below is my webView:

 wv1 = (WebView) findViewById(R.id.webview);
    wv1.getSettings().setJavaScriptEnabled(true);
    wv1.getSettings().setLoadWithOverviewMode(true);
    wv1.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    wv1.setScrollbarFadingEnabled(false);
    wv1.getSettings().setBuiltInZoomControls(true);
    wv1.getSettings().setPluginState(WebSettings.PluginState.ON);
    wv1.getSettings().setAllowFileAccess(true);
    wv1.addJavascriptInterface(new WebViewJavaScriptInterface(this), "Android");
    wv1.getSettings().setSupportZoom(true);
    wv1.setWebViewClient(new MyBrowser());
    wv1.loadUrl("file:///android_asset/a.html");

Is it even possible? No, Not Possible.

Android assets file are kind of resource files, you cannot modify them once you build your apk file.

solution for your problem -

  1. make use of storage file system. (very bad approach since read,write,load operations will be there).
  2. use java script interface and try add styles dynamically to html elements.(ideal one)

    example : Changing element style attribute dynamically using JavaScript

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