Loading local html file in webView android

后端 未结 3 2048
独厮守ぢ
独厮守ぢ 2020-12-24 02:01

I have to load an existing html file into a WebView that is located at this path in the file system:

/data/data/com.example.example/files/file.         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 02:55

    The html file should be placed in the assets folder, which will belong in the root directory of your project.

    So move your file to in case of eclipse

    assets/index.html
    

    In an Android Studio project use this folder:

    /app/src/main/assets/index.html
    

    Now use

    WebView wv= (WebView)findViewById(R.id.webView1);
    wv.loadUrl("file:///android_asset/index.html");
    

提交回复
热议问题