Android:ListView 内的 HTML 链接 - 突出显示问题
我编写了使用 ListActivity
的应用程序。列表中的每个项目均由 ImageView
和 TextView
组成。长按列表条目会触发一些菜单和颜色效果,因为 onCreateContextMenu
已被覆盖。有时 TextView
包含我希望具有交互性的 HTML 链接。我阅读了 #1697908 并激活了链接,因此浏览器/YouTube 播放器启动。一切都会很棒,但长按时的颜色效果消失了(上下文菜单仍然出现)。
有人能告诉我如何连接这两个功能并恢复颜色效果吗?
I wrote application which uses ListActivity
. Each item of the list consists of ImageView
and TextView
. Long click on list entry triggers some menu and color effect because onCreateContextMenu
was overridden. Sometimes TextView
contains HTML links which I would like to be interactive. I read #1697908 and made links active, so browser/youtube player is started. Everything would be great but color effect on long click disappeared (context menu still appears).
Could somebody tell me how to connect these two features and get back color effect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在自定义列表适配器中使用 Linkify。 Linkify 允许您使用选择器设置颜色,如下所示:(
注意:holder.messageText 是 Holder 对象中的简单 TextView),
然后您有一个 /res/color/color_selector.xml,如下所示:
<选择器 xmlns:android="http://schemas.android.com/apk/res/android">
You can use Linkify in a custom list adapter. Linkify allows you to set colors using a selector like so:
(note: the holder.messageText is a simple TextView in a holder object)
then you have a /res/color/color_selector.xml like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@drawable/message_focused" />
<item android:state_pressed="true" android:state_enabled="false"
android:color="@drawable/message_pressed" />
<item android:state_enabled="false" android:color="@drawable/message_enabled" />
<item android:state_active="true" android:color="@drawable/message_active" />
<item android:color="@drawable/message_default" />
</selector>
我一开始使用了 ImageView 和 Textview,但是使用 WebView 可以避免此类问题并保持 html 交互性。
阅读此
如何在 Android 布局中拥有浮动图像(右对齐)以及环绕图像的文本?
I used a ImageView and a Textview at the beginnin, but you can avoid that kind of problems using a WebView and keep the html interactivity.
read this
How can I have a floating image (right aligned) with text that wraps around the image in Android Layout?
我已经成功解决了这个问题。也许不是直接以我想要的方式,但这对我来说已经足够了。我没有将侦听器添加到
TextView
,而是将其添加到整行。突出显示按我的预期工作。这种行为对于我的应用程序来说是可以接受的,但这是某种解决方法,因此我仍然想知道是否可以做得更好。I've managed to solve this issue. Maybe not directly in such a way I wanted but it's enough for me. Instead of adding listener to
TextView
I add it to entire row. Highlighting is working as I expected. This behaviour is acceptable for my app but is some kind of workaround so I still would like to know whether it can be done better.