WebView: webpage not available but I load it from an html string

前端 未结 3 637
一个人的身影
一个人的身影 2021-01-15 02:06

My html string is like this:


3条回答
  •  天命终不由人
    2021-01-15 02:36

    Solved, gimme a lot of "helpful" for this answer because it's really a nasty webview bug and I think my answer will help a lot of you!

    If your html page contains, indeed, one of "%","\" or "#" characters, loadData() method will fail!! So you have to manually replace these chr and here's my class:

    public class BuglessWebView extends WebView{
    
    public BuglessWebView(Context context) {
        super(context);
    }
    
    public BuglessWebView(Context context,AttributeSet attributes){
        super(context,attributes);
    }
    
    public BuglessWebView(Context context,AttributeSet attributes,int defStyles){
        super(context,attributes,defStyles);
    }
    
    @Override
    public void loadData(String data, String mimeType, String encoding) {
    
        super.loadData(solveBug(data), mimeType, encoding);
    }
    
    private String solveBug(String data){
        StringBuilder sb = new StringBuilder(data.length()+100);
        char[] dataChars = data.toCharArray();
    
        for(int i=0;i

    here's discussion link on google code: http://code.google.com/p/android/issues/detail?id=1733

提交回复
热议问题