我有一个 ListView我从自定义 ListAdapter 填充.在适配器内部(在 getView(int, View, ViewGroup) 方法中)我正在设置 View 的背景颜色使用 setBackgroundColor(int) .问题是无论我将背景设置为什么颜色,它总是呈现深灰色。可能还值得注意的是,我使用的是 Light 主题。
相关(简化)代码位:
AndroidManifest.xml:
<activity
android:name=".MyActivity"
android:theme="@android:style/Theme.Light" />
我的适配器.java:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View av = inflater.inflate(R.layout.my_row, parent, false);
av.setBackgroundColor(R.color.myRow_red);
mName = (TextView) av.findViewById(R.id.myRow_name);
mName.setText("This is a name");
return av;
}
有什么想法/建议吗?
最佳答案
你应该使用:
setBackgroundResource(R.color.myRow_red)
而不是 setBackgroundColor()
。 在您的示例中,背景颜色分配有 ID,而不是资源中描述的实际颜色。
关于Android ListView 背景颜色总是显示灰色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1397183/