Loading html file to webview on android from assets folder using Android Studio

前端 未结 3 1524
走了就别回头了
走了就别回头了 2020-12-01 09:34

I\'m using Android Studio/Gradle.

app\\src\\main\\android_asset folder has the file called chart.html..

I\'m trying to load this file to my webview like this

3条回答
  •  攒了一身酷
    2020-12-01 10:07

    The directory name should be assets not android_assets

    Do like this: enter image description here

    As shown in the above pics just right click on your app->New->Folder->Assets Folder

    Now put your .html file here in assets folder.

    That's it. Done.

    Remaining is same in code what you did.

    WebView view = new WebView(this);
    view.getSettings().setJavaScriptEnabled(true);
    view.loadUrl("file:///android_asset/hello.html");
    setContentView(view);
    

提交回复
热议问题