设置列表项的背景颜色失去凸显 [英] Setting list item background color loses highlighting

查看:165
本文介绍了设置列表项的背景颜色失去凸显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个收件箱中的活动,我镜像自带了Android默认的邮件应用程序的一些功能。

I've created an inbox Activity and I'm mirroring some functionality of the default Mail application that comes with Android.

在邮件,消息的背景色尚未读是较亮的颜色比​​在列表中的项目的其余部分。我已经通过设置呼叫setBackgroundResource在我的适配器的getView方法反映这一点。 setBackgroundColor没有做任何事情。

In Mail, the background color of a message that has not been read is a lighter color than the rest of the items in the list. I've mirrored this by setting calling setBackgroundResource in the getView method of my Adapter. setBackgroundColor doesn't do anything.

        if (!msgSum.getIsRead()) {
            LinearLayout l = (LinearLayout) v.findViewById(R.id.inbox_background);
            if (l != null) {
                l.setBackgroundResource(R.color.inbox_unread);
            }
        }
        else {
            LinearLayout l = (LinearLayout) v.findViewById(R.id.inbox_background);
            if (l != null) {
                l.setBackgroundResource(R.color.inbox_read);
            }
        }

的问题是,该物品然后失去能力突出。我的意思是,通常如果您在使用仿真器(或者,如果你的Andr​​oid设备有某种形式的滚动功能,你使用),列表项会变黄一样具有焦点。滚动鼠标滚轮

The problem is, the items then lose the ability to highlight. What I mean is, typically if you scroll your mouse wheel while using the emulator (or if your Android device has some sort of scrolling capability, you use that), the list items will turn yellow like they have focus.

我如何做到我想要做的,而不会丢失突出显示一个列表项的能力吗?

How do I accomplish what I'm trying to do without losing the ability to highlight a list item?

感谢您的帮助

推荐答案

每罗曼盖伊的建议下,我观看了谷歌I / O 2010 - ListView中的世界的视频在YouTube上。围绕分钟31:43,他的职位code,解决这个问题的一个片段。你必须做一些修改,但(我正在开发针对2.1)。首先必须声明的xmlns:在选择标签Android的参数。在你的Java code,你必须调用convertView.setBackgroundResource(R.drawable.yourselector),代替的setBackground(这似乎不再存在)。

Per Romain Guy's suggestion, I watched the "Google I/O 2010 - The world of ListView" video on YouTube. Around minute 31:43, he posts a snippet of code that solves this problem. You must make a couple modifications, though (I'm developing against 2.1). First you must declare the xmlns:android parameter in the selector tag. In your Java code, you must call convertView.setBackgroundResource(R.drawable.yourselector), instead of setBackground (which no longer appears to exist).

这篇关于设置列表项的背景颜色失去凸显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆