Displaying Android asset files in a WebView?

后端 未结 2 444
生来不讨喜
生来不讨喜 2020-11-30 04:59

I have seen various discussions on the problem of serving WebView pages from assets, none of which seemed definitive.

I want to be able to use a webview to display h

2条回答
  •  有刺的猬
    2020-11-30 05:17

    Well, I found something that seems to work (on 1.6 and 2.2), in spite of a warning that it would recurse.

    I also discovered that a css style-sheet link inside the first and second page both work without the following intercept. Odd and it makes me a bit nervous. Thoughts?

    Here's the code:

    WebView wv = (WebView)this.findViewById(R.id.splashWebView);
    wv.setWebViewClient(new WebViewClient() {  
      @Override  
      public boolean shouldOverrideUrlLoading(WebView view, String url)  
      {  
        view.loadUrl(url);
        return true;
      }  
    }); 
    wv.loadUrl("file:///android_asset/html_no_copy/demo_welcome.html");
    

    Here's the file contents:

    demo_welcome.html:
    
    
    
      
        
        Demo Html
        
      
      
        

    Testing One Two Three

    CLICK HERE

    OR HERE test.html: Insert title here

    TEST.HTML

提交回复
热议问题