標籤:android style io color ar 使用 java for sp
1、設定WebView為透明:
android:background="#00000000" android:cacheColorHint="#00000000" WebView.setBackgroundColor(0);
2、WebView 顯示sd卡圖片:
webView.loadDataWithBaseURL(null,"<img src=\"www.2cto.com" />", "text/html", "utf-8", null);
3、WebView顯示字串:
webView.loadDataWithBaseURL("fake://not/needed", s1, "text/html", "utf-8", "");
4、設定WebView中顯示字型的大小:
public static final TextSize[] FONT_SIZES = new TextSize[]{TextSize.SMALLER,TextSize.NORMAL,TextSize.LARGER}; private WebSettings wb; wb = mWebViewRightContent.getSettings(); wb.setTextSize(FONT_SIZES[iFontSizeId]); /*字型大小:*/public enum TextSize { SMALLEST(50), SMALLER(75), NORMAL(100), LARGER(150), LARGEST(200); TextSize(int size) { value = size; } int value; }
5、WebView顯示html檔案時,若要達到和PC上瀏覽器顯示的效果完全一樣,只需對WebView做一下設定即可:
view plaincopy//適應全屏 39適應豎屏 57適應橫屏 mWebView.setInitialScale(39); //注意的是:html隻字體太小的話,在Android手機或開發板上顯示的就相當的小。一般6、7號字型吧!
6、WebView設定漸層:
android:fadingEdge="vertical" android:fadingEdgeLength="20px" //(垂直方向,上下漸層地區為20px)
7、設定WebView可觸摸放大縮小:
mWebView.getSettings().setBuiltInZoomControls(true);
8、WebView雙擊變大,再雙擊後變小,當手動放大後,雙擊可以恢複到原始大小,如下設定:
webView.getSettings().setUseWideViewPort(true);
9、幾種加速WebView載入的方法:
//· 提高渲染的優先順序webView.getSettings().setRenderPriority(RenderPriority.HIGH);//· 使用webView.getSettings().setBlockNetworkImage,把圖片載入放在最後來載入渲染webView.getSettings().setBlockNetworkImage(true);
10、將字串轉換成HTML形式的檔案顯示:
//擷取的字串 String sDetails = cursor.getString(cursor.getColumnIndex("sChinese")); //按行截取字串,將其存放在數組中 String[] str = sDetails.split("\n"); String s1 = ""; //遍曆數組進行判斷,如果條件成立,就添加設定的css樣式 for(int i = 0;i < str.length;i ++){ if(str[i].trim().startsWith("vt.")){ str[i] = "<h3 style=\"font-size:10px; color:#000; background:#FCFCFC; padding:3px 5px;\">" + str[i] + "<h3>" + "\n"; }else if(getMark(str[i].trim())){ str[i] = "<h4 style=\"font-size:10px; color:#F60; font-weight:normal;\">" + str[i] + "</h4>" + "\n"; }else if(str[i].trim().startsWith("〖")){ str[i] = "<span style=\"color:#333; font-size:10px; color:#F60\">" + str[i] + "</span>" + "\n"; }else { str[i] = "<p style=\"line-height:16px; font-size:10px;color:#666;\">" + str[i] + "</p>" + "\n"; } //將修改後的字串拼接起來 s1 += str[i]; } //用WebView將字串以HTML的形式顯示出來 webView.loadDataWithBaseURL("fake://not/needed", s1, "text/html", "utf-8", "");
Android WebView相關屬性