android webview pre[name=code] syntaxHighlighter 代码高亮 博客分类: android androidwebviewpre[name=code]syntaxHighlighter代码高亮
程序员文章站
2024-02-09 22:23:16
...
下载 高亮 js css xml
http://download.csdn.net/download/knight_black_bob/9594538
实战 QQ demo源码(本例中有该应用)
服务器端下载:http://download.csdn.net/download/knight_black_bob/9822551
android eclipse 版:http://download.csdn.net/download/knight_black_bob/9822553
android stdio 版本:http://download.csdn.net/download/knight_black_bob/9822556
博客详细效果图
public final static String syntaxHighlighter = "<script type=\"text/javascript\" src=\"file:///android_asset/shCore.js\"></script>" + "<script type=\"text/javascript\" src=\"file:///android_asset/shBrushCpp.js\"></script>" + "<script type=\"text/javascript\" src=\"file:///android_asset/shBrushXml.js\"></script>" + "<script type=\"text/javascript\" src=\"file:///android_asset/shBrushJScript.js\"></script>" + "<script type=\"text/javascript\" src=\"file:///android_asset/shBrushJava.js\"></script>" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"file:///android_asset/shThemeDefault.css\">" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"file:///android_asset/shCore.css\">" + "<script type=\"text/javascript\">SyntaxHighlighter.all();</script>";
iteye 博客详细内容
public static String getIteyeBlogString(String data){ Element detail = null; Document document =null; try { document = Jsoup.parse(data); detail =document.getElementsByClass("blog_main").get(0); detail.getElementById("bottoms").remove(); detail.getElementsByClass("blog_nav").remove(); detail.getElementsByClass("news_tag").remove(); detail.getElementsByClass("blog_categories").remove(); detail.getElementsByClass("blog_bottom").remove(); detail.getElementsByClass("boutique-curr-box").remove(); detail.getElementsByClass("blog_comment").remove(); detail.getElementsByTag("iframe").remove(); Elements codeElements = detail.select("pre[name=code]"); for (Element codeNode : codeElements) { codeNode.attr("class", "brush: java; gutter: false;"); } } catch (Exception e) { e.printStackTrace(); } return Constants.syntaxHighlighter+ detail.toString(); }
public class IteyeDetailActivity extends BaseActivity { private WebView webView; private String url ="http://blog.csdn.net/jmilk/article/details/52046914"; final String mimeType = "text/html"; final String encoding = "utf-8"; private Context mContext; @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.iteye_list_item_detail); this.mContext = IteyeDetailActivity.this; initUtils(); initView( ); // initListeners(); EventBus.getDefault().register( this ); IteyeHttpRequest.getIteyeBlogData(url); } private void initListeners() { webView.loadUrl(url); //showWaitingDialog(""); /*webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); dismissWaitingDialog(); return true; } }); */ } private void initView() { webView = (WebView) this.findViewById(R.id.wv_qq_news_item_detail_webview); WebSettings settings = webView.getSettings(); settings.setDomStorageEnabled(true); settings.setAllowFileAccess(true); settings. setDefaultTextEncodingName("UTF -8"); settings.setJavaScriptEnabled(true); //支持js //settings.setPluginsEnabled(true); //支持插件 settings.setUseWideViewPort(false); //将图片调整到适合webview的大小 settings.setSupportZoom(true); //支持缩放 settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); } private void initUtils() { Intent intent = getIntent(); Bundle bundle = intent.getBundleExtra("bundle"); url =bundle.getString(IteyeMainActivity.ITEYE_DETAIL_URL); } public void onEventMainThread(RequestEvent requestEvent){ if(requestEvent instanceof IteyeStringHttpEvent){ IteyeStringHttpEvent event = (IteyeStringHttpEvent) requestEvent; switch(event.status){ case HTTP_ERROR: break; case HTTP_SUCCESS: { String result = event.data; String data = IteyeJsoupPerformer.getIteyeBlogString(result); String shtml = IteyeJsoupPerformer.getHtml(data); //webView. loadData(iteyeBlogString, "text/html", "UTF-8") ; webView.loadDataWithBaseURL( "file:///android_asset/", shtml, "text/html", "utf-8", null ); } break; default: break; } }else{ } } @Override public void onDestroy() { EventBus.getDefault().unregister( this ); super.onDestroy(); } }
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!