简体   繁体   English

HTML <marquee> 标签阻止在Android WebView中显示数据

[英]Html <marquee> tag is preventing to display data in Android WebView

I want to display some text with continuous moving behavior in webview. 我想在webview中显示一些具有连续移动行为的文本。 When I use marquee tag in html, then the webview doesn't show any data or text. 当我在html中使用选取框标记时,则webview不会显示任何数据或文本。 But without the marquee tag it show's data/text. 但是没有字幕标记,它显示的是数据/文本。 How can I solve this issue ? 我该如何解决这个问题?

Please note that, I am suffering with this problem in Nexus and Samsung devices with kitkat and lollypop version of android. 请注意,我在带有kitkat和lollypop版本的android的Nexus和Samsung设备中遇到此问题。

Here is my java code: 这是我的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);

Here is the XML code for WebView: 这是WebView的XML代码:

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

The marquee tag is known to possibly not work in all cases. 众所周知,跑马灯标签可能并非在所有情况下都有效。 To quote from MDN : 引用MDN

Non-standard 非标
This feature is non-standard and is not on a standards track. 此功能是非标准的,不在标准轨道上。 Do not use it on production sites facing the Web: it will not work for every user. 请勿在面向Web的生产站点上使用它:它不适用于每个用户。 There may also be large incompatibilities between implementations and the behavior may change in the future. 实现之间也可能存在很大的不兼容性,并且将来的行为可能会更改。

But, if you still want to use it, this comment should help: 但是,如果您仍然想使用它,则此注释应该会有所帮助:

Just CSS - http://jsfiddle.net/4mJQ6/2 . 只是CSS- http://jsfiddle.net/4mJQ6/2 Can add other browser support to it 可以添加其他浏览器支持

The fiddle is reproduced below: 小提琴复制如下:

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM