Android webview.loadData() 不显示选项卡

new*_*544 0 css android webview

我对 css 和 android 很陌生。我正在尝试在网络视图中加载要点,但是当我使用时代码的缩进没有出现当webview.loadData(content, "text/html", "utf-8");我使用时它运行良好webview.loadUrl(url);,但我想要前一个。我在这里错过了一些大事吗?哦,缩进是通过 css property 来体现的white-space: pre;。这是我的代码:

final WebView webview = (WebView)getActivity().findViewById(R.id.algoView);
webview.getSettings().setJavaScriptEnabled(true);
//webview.loadUrl("https://gist.github.com/tanaykumarbera/c9f7f3e7490a1c002649/" ); // works perfectly

AsyncHttpClient client = new AsyncHttpClient();
client.get("https://gist.github.com/tanaykumarbera/c9f7f3e7490a1c002649", new AsyncHttpResponseHandler() { 

        @Override
        public void onStart() {
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] res) {
            String data="";
                ByteArrayInputStream b = new ByteArrayInputStream(res);
                String response = "";int c;
                while( (c = b.read()) != -1) {
                    response += Character.toString((char) c);
                }
                webview.loadData(response, "text/html", "utf-8"); // Not Working!!
        }

        @Override
        public void onFailure(int statusCode, Header[] headers,  byte[] errorResponse, Throwable e) {
        }

        @Override
        public void onRetry(int retryNo) {
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

截图:

http://postimg.org/image/rjz6e18fv/

http://postimg.org/image/u2kvepu63/

任何关于如何在本地加载它或者我应该阅读原始降价的想法将不胜感激!

new*_*544 5

经过很长一段时间的摆弄后,我发现而不是

 webview.loadData(response, "text/html", "utf-8");
Run Code Online (Sandbox Code Playgroud)

使用

webview.loadDataWithBaseURL("", response, "text/html", "utf-8", null);
Run Code Online (Sandbox Code Playgroud)

修复了这个问题,尽管我不知道为什么 css 选项卡不能与以前的代码一起使用。