2015-03-02 146 views
0

我需要顯示在gmail應用程序中顯示的html內容,顯示更具可讀性的消息內容。實現LayoutAlgorithm.SINGLE_COLUMN算法?

我嘗試的第一步是將自定義和通用的CSS應用於所有消息內容。但對於媒體查詢並沒有很好的反應,而且它在各種內容中都有所不同。此外,圖像不是正確的比例。

所以我決定使用LayoutAlgorithm.SINGLE_COLUMN。除了多列表格外,它的工作原理與我對較低設備的預期完全相同。但對於設備> ktikat,它似乎已被棄用。

有沒有其他方法可以實現LayoutAlgorithm.SINGLE_COLUMN算法?還是有任何替代品?任何幫助深表感謝。

回答

0

word-wrapping no longer supported

在Android中4.4(奇巧)起與鉻的整合,文本回流從Web視圖中移除。

有論壇在討論這個問題,並且已經得到類似這個問題的答覆已被宣佈爲「按照預期工作」,並且項目成員已經明確表示沒有計劃改變課程。

這是中提到:

「調用這個錯誤可能會有點不準確的 - 這似乎是谷歌意在去除文本重排也許搜索巨頭真的是厭倦了等待的Web開發人員支持移動。設備,並決定採取更積極的態度,也許這只是谷歌推出改進後的智能算法的前身,畢竟,將內容壓縮到一個窄列中的方法有點不切實際,並且傾向於擁有自己的無論這種情況如何,除了希望從網絡開發這個更加偉大的世界中快速轉變外,我們所能做的並不多。「

0

如您所知,SINGLE_COLUMN算法會將一些樣式應用於給定的html頁面,以將html內容放置在單個列中。因此,我們可以通過將CSS注入加載的html頁面的<head/>部分來更改html頁面的樣式屬性。包括的步驟有:

  1. 以編程方式下載html源文件並將其存儲爲String對象。
  2. 注入你的CSS樣式到html頁面。即,您必須準備一個將覆蓋html頁面上所有其他樣式的CSS樣式。

  3. 在您的java代碼中,通過調用​​將CSS注入下載的html字符串,然後將返回的htmlString加載到webview。

    // bufferHtmlString有html源代碼 webView.loadData(injectCssToHtmlCode(bufferHtmlString。toString()),「text/html」,「utf-8」);

  4. 方法​​,

\t private String injectCssToHtmlCode(String downloadedHtmlCode) { 
 
\t \t String head = "<head><meta name='viewport' "+ 
 
\t \t \t \t "content='initial-scale=1.0, "+ 
 
\t \t \t \t "maximum-scale=1.0, "+ 
 
\t \t \t \t "minimum-scale=1.0, "+ 
 
\t \t \t \t "height=device-height, "+ 
 
\t \t \t \t "width=device-width, "+ 
 
\t \t \t \t "target-densityDpi=device-dpi' /> "+ 
 
\t \t \t \t " \t \t <style type='text/css'> \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t " \t html.body {width:50% !important; height:auto !important; max-width:100% !important; } \t "+ 
 

 
" \t body {word-break:break-all !important; margin:0px !important; padding:2px !important; }"+ 
 
" \t h1 {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; }"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t h2 {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; } \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t h3 {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; } \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t h4 {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; } \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t h5 {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; } \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t h6 {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; } \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t hr {max-width:100% !important; height:auto !important; margin-left:0px !important; margin-right:0px !important; padding:1px !important; border:none}"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 

 
" \t p {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; width:100% !important; word-wrap: break-word !important;} "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t pre {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; white-space:pre-wrap !important; }"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t form {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; width:100% !important; word-wrap: break-word !important;} \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 

 
" \t dl {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; width:100% !important; word-wrap: break-word !important;} \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t ul {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px 1em !important; width:100% !important; word-wrap: break-word !important;} \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t ol {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px 1.5em !important; width:100% !important; word-wrap: break-word !important;}"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t dir {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; width:100% !important; word-wrap: break-word !important;} \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t div {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; background-color:#FF0055 !important; width:100% !important; word-wrap: break-word !important;} \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 

 
" \t marquee {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; } \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t table {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; word-wrap: break-word !important;}"+ \t 
 
" \t table input[type='text'] {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; width:100% !important; word-wrap: break-word !important;}"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t table input[type='file'] {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; width:100% !important; word-wrap: break-word !important;}"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t table textarea {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; width:100% !important; word-wrap: break-word !important;} \t "+ 
 

 
" \t tr {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; word-wrap: break-word !important;} \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t td {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; word-wrap: break-word !important;} \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t input {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; word-wrap: break-word !important;} \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t textarea {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; word-wrap: break-word !important;}"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t select {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; } \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t a {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; word-wrap: break-word !important;} \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t object {max-width:100% !important; height:auto !important; margin:1px 0px !important; padding:2px 0px !important; }"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t img {max-width:100% !important; margin:1px 0px !important; padding:2px 0px !important; } \t \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t marquee[behavior='alternate'] {display:block !important; overflow:-webkit-marquee !important; max-width:100% !important; -webkit-marquee-style:alternate !important; } \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t .wb{word-break:break-all !important; } \t "+ 
 

 
" \t @-webkit-keyframes blink { \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t 0% { opacity: 0 } \t \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t 50% { opacity: 0 } \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t 50.01% { opacity: 1 } 100% { opacity: 1 }"+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t } \t \t \t \t \t \t \t \t \t \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t blink { \t \t \t \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t -webkit-animation: blink 0.7s infinite linear alternate !important; \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t -webkit-font-smoothing: antialiased !important; \t \t \t \t \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
" \t } \t \t \t \t \t "+ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 

 
"</style></head>"; 
 
\t \t return "<html>" + head + "<body>" + downloadedHtmlCode + "</body></html>"; 
 
\t }

+0

抱歉PAL。這個CSS不適合所有類型的內容 – arul 2015-03-14 15:49:49