2015-05-26 58 views
0

我想在webview中顯示一些帶有連續移動行爲的文本。當我在html中使用選取框標記時,webview不顯示任何數據或文本。但沒有選框標籤顯示的數據/文本。我該如何解決這個問題?Html <marquee>標記阻止在Android WebView中顯示數據

請注意,我在Nexus和三星設備的kitkat和lollypop版本的android中遇到了這個問題。

這裏是我的Java代碼:

String tickerString = "<html><body><marquee>"+someTextIncludingHtmlAndCSS+"</marquee></body></html>"; 
WebView tickerWebView=(WebView)findViewById(R.id.tickerWebView); 
tickerWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 
tickerWebView.getSettings().setJavaScriptEnabled(true); 
tickerWebView.loadDataWithBaseURL(null,tickerString ,"text/html", "utf-8", null); 

這裏是WebView中的XML代碼:

<WebView 
      android:id="@+id/tickerWebView" 
      android:layout_width="match_parent" 
      android:layout_height="40dp" 
      android:background="#ffffff" /> 

回答

0

選框標籤是衆所周知的可能不是在所有情況下工作。若要從MDN引用:

非標準
此功能是非標準的,而不是一個標準的軌道。不要在面向Web的生產站點上使用它:它不適用於每個用戶。實現之間也可能存在很大的不兼容性,並且行爲在未來可能會發生變化。

但是,如果你仍然想使用它,this comment應該有所幫助:

只是CSS - http://jsfiddle.net/4mJQ6/2。可以把它

添加其他瀏覽器支持的小提琴轉載如下:

p.marquee{ 
 
    -webkit-animation-name: marquee; 
 
    -webkit-animation-timing-function: linear; 
 
    -webkit-animation-duration:10s; 
 
    -webkit-animation-iteration-count: infinite; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    display: block; 
 
    white-space: nowrap; 
 
} 
 

 

 
@-webkit-keyframes marquee{ 
 
    0%{ 
 
     text-indent: 95%; 
 
} 
 
    100%{ 
 
     text-indent: -20%; 
 
    } 
 
}
<marquee>wow old school marquee</marquee> 
 
<p class='marquee'>wow css3 marquee fun!</p>

+0

那麼什麼是這個標籤的選擇嗎?或者我該如何實現我的目標 –

+0

@KhaledSaif更新。 – Anonymous