Problems loading html asset into webview

后端 未结 2 967
清酒与你
清酒与你 2020-12-11 11:08

I am having difficulty in loading a html file from my project assets folder into a webview. I have looked at dozens of tutorials and solutions but none seem to work for me.

相关标签:
2条回答
  • 2020-12-11 11:12

    your usage is right, so if has this problem, you need check the index.html file existed or not carefully, also you can clean the project, and rebuild it.

    0 讨论(0)
  • 2020-12-11 11:25
    You can try this code ....
    

    WebView myBrowser;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            String myURL = "file:///android_asset/index.html";
            myBrowser=(WebView)findViewById(R.id.mybrowser);
    
            /*By default Javascript is turned off,
             * it can be enabled by this line.
             */
            myBrowser.getSettings().setJavaScriptEnabled(true);
            myBrowser.setWebViewClient(new WebViewClient());
    
            myBrowser.loadUrl(myURL);
    
        }
    
    0 讨论(0)
提交回复
热议问题